2013-03-12 28 views
0

我在我的应用程序中使用ACL。我已经在我的AppController中的beforeFilter中定义了我的loginAction,但它仍然没有重定向到正确的位置。当用户访问应用程序就像这是我想要做的是 - 本地主机/ IntraWeb的,必须重定向然后到localhost/IntraWeb的/用户/登录在Cakephp中使用Acl时,LoginAction不起作用

这里是我的AppController代码

class AppController extends Controller { 

public $helpers = array('Html', 'Form', 'CustomFields.Field'); 

public $components = array(
'CustomFields.Field', 
'Acl', 
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers') 
) 
), 
'Session', 
'Cookie', 
); 

public $uses = array('User'); 

public function beforeFilter() {  

//Configure AuthComponent 
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); 
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'login'); 
$this->Auth->allow('display'); 

//OTHER CODE 

} 

和这里我的PagesController代码

class PagesController extends AppController { 

public function beforeFilter() { 
parent::beforeFilter(); 
$this->Auth->allow(); 
} 

//Other code 

有没有人有一个想法,为什么它不重定向到用户/登录页面?

预先感谢您

回答

0

的loginRedirect行动手段,当找不到验证会议呼叫。简单来说就是一个登录页面。不需要认证就允许通过的动作不会重定向到loginRedirect。

当您访问localhost/intraweb时,Cake会呈现Pages/display,因为您的代码中有$this->Auth->allow('display');。 Auth将允许它在不重定向到loginRedirect的情况下呈现。

更新:

重新声明beforeFilter()在其他控制器过骑在AppController的所有声明。所以,如果从AppController中的beforeFilter()声明要继承,

public function beforeFilter() { 
    parent::beforeFilter(); // inherit beforeFilter() from AppController 
    // your controller specific declarations 
} 
+0

我想我错过了这里的一些小东西。我编辑了我的代码,甚至删除了$ this-> Auth-> allow('display'); 。但仍然不想将我重定向到登录页面。任何想法可能会导致这一点? – 2013-03-12 17:26:52

+0

你有BeforeFilter()在PagesController中定义? – 2013-03-12 17:28:13

+0

是的,我在我的PagesController中有一个beforeFilter()。我现在删除了作品。谢谢 – 2013-03-12 20:04:49