2012-07-16 78 views
2

我得到一个重定向循环错误,为我的生活我无法弄清楚如何或为何重定向循环。这里是我的设置:CakePHP的2:验证

路由器

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); 

AppController的

class AppController extends Controller { 
    public $components = array(
     'DebugKit.Toolbar', 
     'Acl', 
     'Auth' => array(
      'authorize' => array('Actions' => array('actionPath' => 'controllers')), 
      'loginAction' => array('controller' => 'users', 'action' => 'login'), 
      'loginRedirect' => array('controller' => 'users', 'action' => 'index'), 
      'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home') 
     ), 
     'Session' 
    ); 
    var $helpers = array('Html', 'Form', 'Session'); 

    public function isAuthorized($user){ 
     return true; 
    } 

    function beforeFilter() { 
    } 
} 
+0

超级老问题,我知道,但是这是固定我的问题:'父:: beforeFilter();'。 – 2013-07-25 21:40:34

回答

2

这可能是因为你没有设置显示()方法为public。这就是为什么它可能会重定向到同一页面,并且该网页未经过身份验证。

所以,你可以把你“display()方法”在页面控制器公众开放使用下面的代码:

//Define following method in your controller PagesController.php 
function beforeFilter() 
{ 
     $this->Auth->allow('display'); 
} 

希望它会为你工作。请问是否为你工作。

+1

我的想法是,无需在AppController中为Auth Component初始设置指定IsAuthroized()方法。您可以稍后尝试使用它。 – 2012-07-16 04:52:04

+1

使用$ this-> Auth-> allow()来指定ANYONE可以查看哪些动作。 使用isAuthorized()来决定特定用户是否可以访问某个操作。 如果Auth->允许()设置为允许访问 '显示',isAuthorized()将不会被调用显示行动 - Auth->允许()覆盖isAuthorized() – RichardAtHome 2012-07-16 15:45:02

+0

使用$这个 - > requestAction( )在视图中可能包含其他控制器。确保他们有正确的权限。 – Tal 2014-06-05 10:08:55