我刚开始学习Auth组件,但我在重定向方面遇到了问题。我的本地应用程序的路径是: localhost/school,但是当一个登录的用户试图访问一个url时,他不被允许,站点会重定向到localhost/校/校,并显示“请求的地址‘/学校/学校/’在这个服务器上找不到”。当这种情况发生时,我不想重定向,只是在同一页面中显示“您不被允许”,或者可能重定向到特定的错误页面,我该怎么做呢?我没有登录或注销重定向的问题,只是我之前说过的。这是我的App Controller:
公共$components =数组( 'Acl','Auth‘=>数组(’授权‘=>数组( 'Actions’控制器数组(‘actionPath’=>‘=>’),‘会话’);公共$helpers =数组(‘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.";
}发布于 2014-10-15 02:26:52
如果您不允许某人访问页面,那么当他们请求访问时,您希望控制器做什么?
例如,您可以使用以下命令设置重定向:
$this->redirect(array(
'controller'=>'users',
'action' => 'login'));`您可以使用Session::setFlash();显示消息
发布于 2014-10-21 22:40:40
当您没有权限执行此操作时,localhost/projectName/projectName是重定向。我也有同样的问题。我在$components中评论了一下'Actions' => array('actionPath' => 'controllers') )。在此之后,我通过执行以下代码来设置aros_acos:
$group = $this->User->Group->read(null,'1');
$this->Acl->allow($group, 'controllers/Users/controlPanel');在那之后,我取消对代码的注释,并且在操作中'controlPanel‘和错误消失:)我不知道如何改变这个重定向,但是如果我在aros_acos中有记录,一切都会正常工作。
发布于 2015-01-07 13:55:33
我也有同样的问题,我解决了它。
在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();
}https://stackoverflow.com/questions/26363825
复制相似问题