Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
User Model
  • Hi

    I am trying to create a user model (non-ORM) that I can simply reference throughout the app (i.e. \User::currentUser) to get various details about the user after logged in.  Please see attached model.  No matter what I try, I can not access the variable I have set from my process_login function (I tried imitating functionality from the SimpleAuth login class).  I keep getting [30-Apr-2013 21:19:36 America/New_York] PHP Fatal error:  Using $this when not in object context in /home/poochfin/public_html/fuel/app/classes/model/user.php on line 144.  Also, if setup this way, will I be able to access the singular User instance (and the current logged in user) throughout the app?  Thanks

  • HarroHarro
    Accepted Answer
    You're mixing static and non-static use.

    $user is defined as an object property (not static), but you're not in an object context when you call something statically. Which is why you get the error, there is no object, therefore there is no $this.

    Change it to:

    protected static $user = null;

    And change $this->user to static::$user.
  • Works.  Thank you!

Howdy, Stranger!

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

In this Discussion