Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Get id from simpleauth?
  • Hi,

    I was trying to get the id of the logged in user, and am failing miserably. At first i tried Auth::get('id'); but it returns empty. Then i tried Auth::get_user_id(); and it complains

    Fuel\Core\PhpErrorException [ Notice ]:

    Undefined index: id



    PKGPATH/auth/classes/auth/login/simpleauth.php @ line 482

    This line is return array($this->id, (int) $this->user['id']); and the id it's complaining about is the $this->user['id']. I dumped $this->user and it has all the fields of the simepleauth table, except id.

    What am i missing?
  • HarroHarro
    Accepted Answer
    get_user_id() is the method to use. The docs (http://docs.fuelphp.com/packages/auth/simpleauth/usage.html#/method_get_user_id) gives examples of how it works.

    The question is why your user object doesn't have an 'id' field, as it is required, and get_user_id() uses it too (hence the error message).

    Since $this->user is filled directly from a DB query, there are only two possible options:
    - your table doesn't contain an 'id' column
    - you have configured "table_columns" in the "simpleauth" config file, and have not included "id"
  • I had configured "table_columns" in the "simpleauth" config file, and had not included "id".
  • cool, problem solved then! ;-)

Howdy, Stranger!

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

In this Discussion