按照本教程完成ACL的完整实施后,我的Cake Php项目重定向到了错误的网址 - > http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html
问题 -
正确重定向 - >本地主机/应用程序的名字/
实施ACL后重定向 - >本地主机/应用程序的名字/应用程序的名字/
这是登录后发生的重定向。公共页面(登录)工作正常。
下面是Appcontroller代码 -
public $components = array( 'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
public $helpers = array('Html', 'Form', 'Session');
// only allow the login controllers only
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('login');
}
Acos表截图
Aros表截图
Aros_Acos表截图
分组表
routes.php文件
Router::connect('/dashboard', array('controller' => 'dashboards', 'action' => 'index'));
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
Router::connect('/', array('controller' => 'dashboards', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
当我只使用" Auth"时,正确的网址正在打开而不是以下。
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
但是,ACL无效。
答案 0 :(得分:0)
根据您粘贴的代码,您似乎没有配置登录重定向。我希望您的app控制器中的beforeFilter看起来更像这样:
public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'foo',
'action' => 'bar'
);
$this->Auth->loginRedirect = array(
'controller' => 'foo',
'action' => 'bar'
);
}
在您的情况下,您似乎希望登录用户返回主页,因此在此示例中,您的主页将在app / config / routes.php中定义为foo控制器的条形操作。
在您定义登录操作的控制器(通常是用户控制器)中,您还可以添加重定向,例如:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
// Redirect the user to home
return $this->redirect($this->Auth->redirect(array('controller'=>'foo', 'action'=>'bar')));
}
}
}
您似乎缺少AppController组件数组中的ACL组件。尝试将其更新为:
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);