Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to relate the Ormauth user model to other models?
  • I'm using Ormauth, I need to use the Auth_User model in my application and related to other models. I know the EVA model that it uses but I find it better to use a different model to maintain extra information related to the user. For example I have Profile model that has extra information, like first_name, last_name, address etc. I also have other models that directly relate to the Auth_User model, so how do I do it? 

    Do I go down to the ORM package and edit the Auth_User model itself or is there a better way to do it?

  • HarroHarro
    Accepted Answer
    The model is in the Auth package, and, like all other classes it's aliased to the global namespace, so you can extend it like any other Auth class.

    create app/classes/model/auth/user.php:

    namespace Model;
    class Auth_User extends \Auth\Model\Auth_User {}

    Note that if you change it, certain functions of Auth no longer work, as they require the EAV table to be there.


  • I did try something like that just extended Auth_User model with a class called User and used to get that EVA error you just mentioned. Thanks a lot for the help, as usual!
  • I just tried out your suggestion it works but I can't access newly defined methods and variables. For example in my new Auth_User class, I have the method with the following signature,

    public static function get_picture($user, $type)

    When I try to call that method, I'm getting the following error:

    Fuel\Core\FuelException [ Error ]: Invalid method call. Method get_picture does not exist.
    What does it mean? Can I not add functions and properties to the newly extended class? How do I fix this problem?
  • When doing what?

    \Model\Auth_User::get_picture() should do it.
  • That's not working for me here is what I'm getting

    Fuel\Core\FuelException [ Error ]: Invalid method call. Method get_picture does not exist.

    PKGPATH/orm/classes/model.php @ line 636


    Looks like it's searching for the method in the original Auth_User class, but I've added the class that extends the Auth_User class in my application as you've pointed out earlier but it doesn't seem to work. 
  • HarroHarro
    Accepted Answer
    Have you added your custom class to the app bootstrap, so Fuel knows it exists?

    See http://docs.fuelphp.com/general/extending_core.html#/extend_and_replace
  • That is exactly what I was thinking, I should have done that in order to override the original Auth_User class. Although, that was not exactly what I want to do, it's a great tip to keep in mind for the future. 

    I actually made changes to the new model, I put it in app/classes/model/user.php and defined my class as follows: 

    class Model_User extends Auth\Model\Auth_User {
    ...
    }

    Then I copy and pasted the existing Auth relationships since I'm only going to adding to those. I can now access my EVA attributes. Next thing to check is if I can relate the model to another model and be able to access it.

    Thanks for the help Harro
  • You also have to do that if you extend the original class. Point is that if you request Model\Auth_User, it loads your version instead of the original one.

    If you make a derived class, like you do now, note that it works only in your controller, all Auth code will continue the original model. Also, since ORM caches objects, you might increase the load on the system because it will not be able to utilize the cache, as a Model\Auth_User object is not a Model_User object, even though it maps to the same record.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion