I am attempting to log in users with:
$login = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), TRUE);
However it fails when trying to set the autologin cookie, with ErrorException [ Notice ]: Trying to get property of non-object
when it gets to:
// Token data
$data = array(
'user_id' => $user->pk(),
'expires' => time() + $this->_config['lifetime'],
'user_agent' => sha1(Request::$user_agent),
);
// Create a new autologin token
$token = ORM::factory('User_Token')
->values($data)
->create();
// var_dump($token); // null
// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
If I var_dump($token)
it says it is null
. I have checked the database and it appears to be added correctly. My config has driver => 'ORM'
. Logging in works if the remember me flag is set to FALSE. Why is $token not an object? Is there something I have missed?
I caused the error by overriding the create()
method in class ORM_Base extends Kohana_ORM
which then called the parent::create()
but directed the user_token to the wrong create(). Fixed by removing the create() I added.