0
我想访问当前登录的id
用户如何在cakePHP中的函数beforeDelete()中获取当前登录用户的ID?
我beforeDelete()
功能/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;
}
}
但在执行过程中,我得到以下错误:
Notice (8): Undefined property: Course::$Auth [APP/models/course.php, line 86]
Fatal error: Call to a member function user() on a non-object in /var/www/some_path/app/models/course.php on line 86
请建议。
组件(如Auth组件)仅可用于控制器。所以这就是为什么你会得到错误。我不知道如何以一种干净的方式解决这个问题。 – Arjen 2011-06-16 13:59:55
感谢@Terr。 burzum建议的方法工作 – 2011-06-16 14:41:07