not getting user id from from Auth::instance->get_user()-id in Kohana
I am using auth module of kohana. I did register and login and its working fine. But when i do Auth::instance()->get_user()->id
i get NULL
While login i do it 开发者_StackOverflow中文版with Auth::instance()->login($validator['email'], $validator['password'])
and then redirect user to home page.
But when in one of the controller i do Auth::instance()->get_user()->id
i get NULL
What would be the cause. Is that i have to first set something???
Try Auth::instance()->get_user()->pk()
.
pk()
is for primary key.
Works in KO3.
My Mistake
In the _login
function of modules/auth/classes/kohana/auth/orm.php
In that i was doing the following
$user = ORM::factory('user');
$user->where('email', ' = ', $email)
->and_where('password', ' = ', $password)
->find();
// TODO remember to be done
if ($user !== null) {
$this->complete_login($user);
return true;
} else {
return false;
}
In above i was checking $user is null or not but if the email and password not match the user instance will be created with NULL
values for all the columns.
So now i am checking $user->id !== NULL
and it is working fine.
Try this:
if ($user->loaded()) {
$this->complete_login($user);
return true;
} else {
return false;
}
See ORM::__call() if you want to know what happends (since ORM::loaded() does not exist)
精彩评论