在实施ACL后将Cake php 2.x项目重定向到错误的URL [英] Cake php 2.x project redirecting to wrong url after ACL implementation
问题描述
在我按照本教程的完整实施ACL之后,我的Cake Php项目正在重定向到错误的URL-> http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl -受控应用程序/简单acl受控应用程序.html 。
My Cake Php project is redirecting to the wrong url after I did the full implementation of ACL by following this tutorial -> http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html.
问题-
正确的重定向-> localhost / appname /
Correct redirect -> localhost/appname/
在实施ACL之后重定向-> localhost / appname / appname /
Redirect after I implemented ACL -> localhost/appname/appname/
这是登录后发生的重定向。公用页面(登录)工作正常。
This is the redirect that occurs after login. The public pages (Login) work fine.
下面是Appcontroller代码-
Below is Appcontroller code-
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表格截图
组表
Acos table screenshot
Aros table screenshot
Aros_Acos table screenshot
groups table
Routes.php
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而不是以下内容时,正确的URL正在打开。
The right url was opening when I used only "Auth" instead of the following.
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
但是,ACL不起作用。
推荐答案
根据您粘贴的代码,您似乎尚未配置登录重定向。我希望您的应用控制器中的beforeFilter看起来像这样:
From the code you've pasted you don't seem to have configured a login redirect. I would expect your beforeFilter in your app controller to look more like this:
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控制器的bar操作。
In your case you appear to want the logged in user to return to the home page so in this example your home page would be defined in app/config/routes.php as being the bar action of the foo controller.
在您定义的控制器中登录操作(通常是用户控制器),您还可以添加重定向,例如:
In the controller where you define the login action (normally the users controller) you may also add a redirect, something like:
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组件。尝试将其更新为:
You seem to be missing the ACL component in your AppController components array. Try updating it to:
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
这篇关于在实施ACL后将Cake php 2.x项目重定向到错误的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!