$controller 没有在 cakephp 中实现 isAuthorized() 方法
$controller does not implement an isAuthorized() method in cakephp
我在我的 OrdersController 中使用了 Auth 组件,如下所示:
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email', //Default is 'username' in the userModel
'password' => 'password' //Default is 'password' in the userModel
),
'userModel' => 'Agent'
)
),
'loginAction' => array(
'controller' => 'admins',
'action' => 'login'
),
'loginRedirect' => array('controller' => 'admins', 'action' => 'deshboard'),
'logoutRedirect' => array('controller' => 'admins', 'action' => 'login'),
'authError' => "You can't acces that page",
'authorize' => 'Controller'
)
);
public function beforeFilter() {
parent::beforeFilter();
// Allow users to register and logout.
$this->Auth->allow('login','index');
}
当我尝试登录并且用户名和密码匹配时,它重定向到 adminc/deshboard,并出现以下错误消息:
$controller does not implement an isAuthorized() method.
Error: An Internal Error Has Occurred.
我搜索了 google 几个小时没有解决方案。我在为这个错误做什么?谢谢你的时间。
您需要实施 isAuthorized()
,如下所示:
class OrdersController extends Controller {
//...
public function isAuthorized($user) {
//auth check
//return boolean
}
//...
}
有关详细信息,请参阅 http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html。
我在我的 OrdersController 中使用了 Auth 组件,如下所示:
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email', //Default is 'username' in the userModel
'password' => 'password' //Default is 'password' in the userModel
),
'userModel' => 'Agent'
)
),
'loginAction' => array(
'controller' => 'admins',
'action' => 'login'
),
'loginRedirect' => array('controller' => 'admins', 'action' => 'deshboard'),
'logoutRedirect' => array('controller' => 'admins', 'action' => 'login'),
'authError' => "You can't acces that page",
'authorize' => 'Controller'
)
);
public function beforeFilter() {
parent::beforeFilter();
// Allow users to register and logout.
$this->Auth->allow('login','index');
}
当我尝试登录并且用户名和密码匹配时,它重定向到 adminc/deshboard,并出现以下错误消息:
$controller does not implement an isAuthorized() method.
Error: An Internal Error Has Occurred.
我搜索了 google 几个小时没有解决方案。我在为这个错误做什么?谢谢你的时间。
您需要实施 isAuthorized()
,如下所示:
class OrdersController extends Controller {
//...
public function isAuthorized($user) {
//auth check
//return boolean
}
//...
}
有关详细信息,请参阅 http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html。