我刚刚开始学习 Auth 组件,但在重定向方面遇到了问题。我的本地应用程序的路径是: localhost/school 但是当登录的用户尝试访问某个网址时,他不允许该网站重定向到 localhost/school/school 并显示“请求的地址 '/school/school/'在这个服务器上没找到”。发生这种情况时,我不希望重定向,只需在同一页面中显示“您不允许”,或者重定向到特定的错误页面,我该怎么做?我的登录或注销重定向没有问题,只有我之前所说的问题。这是我的应用程序控制器:
公共$组件=数组(
'阿克',
'验证' => 数组(
'授权' => 数组(
'动作' => 数组('actionPath' => '控制器')
)
),
'会议'
);
public $helpers = array('Html', '表单', '会话');
public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'login'
);
$this->set('current_user',$this->Auth->User());
$this->Auth->authError = "You're not allowed.";
}
我有同样的问题,我解决了。
在 AppController 中尝试此代码
public function beforeFilter() {
//Configure AuthComponent
// note just these two lines
$this->Auth->unauthorizedRedirect=FALSE ;
$this->Auth->authError="Access Denied";
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->loginRedirect = array(
'controller' => 'posts',
'action' => 'add'
);
$this->Auth->allow('display');
//$this->Auth->allow();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)