I want to access the id
of currently logged in user
My beforeDelete()
function in /app/models/course.php
:
function beforeDelete()
{
// Some code
// code also sets value of $uid2
$uid = $this->Auth->user('id'); //this is line 86 in course.php
if ($uid2 == $uid) {
return true;
}
else {
return false;
}
}
But during execution, I get the following error:
Notice (8): Undefined property: Course::$Auth [APP/models/course.php, line 86]
Fatal error: Call to a member function user() on a non-object 开发者_如何学Pythonin /var/www/some_path/app/models/course.php on line 86
Please suggest..
Pass the id of the current logged in user with the data to the model from the controller.
$this->Model->data[$this->Model->alias]['user_id'] = $this->Auth->user('id');
In your beforeDelete() callback you can access it
$this->data[$this->alias]['user_id']
and do whatever you want there. I could give you further advice but your question is, to be honest, not very informative. Please be more specific about your goal in the future.
精彩评论