2013-03-17 52 views
0

当我尝试使用Google的搜索找到解决方案后,我仍然没有找到任何帮助我的东西。问题很简单,我想使用另一个模型进行用户认证。手册显示我们的方式在某种程度上不起作用。AuthComponent userModel仍然执行用户登录

我AppController中看起来像如下:

public $components = array(
     'Auth', 
     'DebugKit.Toolbar' 
    ); 

    public function beforeFilter() 
    { 
     parent::beforeFilter(); 
     if (isset($this->request->params["intranet"]) && $this->request->params["intranet"] == 1) { 
      $this->Auth = array(
      "loginAction" => array(
       "intranet" => true, 
       "controller" => "employees", 
       "action" => "login" 
      ), 
      "authenticate" => array(AuthComponent::ALL => array("userModel" => "Employee")) 
     ); 
      $this->layout = "intranet"; 
     } 
    } 

不要紧,我开什么网址,CakePHP的总是重定向我/用户/登录。当然,我在控制器中运行parent :: beforeFilter()。

编辑:好好像我missunderstand 的usermodel则loginAction似乎这里是正确的关键字,但之后,我把它改为阵列(“控制器” =>“雇员”,“行动” = >“登录”)它仍然将我重定向到/用户/登录...

+0

你有没有尝试把'parent :: beforeFilter()'放在方法的* end *处? – thaJeztah 2013-03-17 22:00:37

回答

0

哦,我的上帝,我是如此愚蠢......我猜大多数程序员已经有一个facepalm后阅读此,但对于较新的CakePHP/PHP开发人员可能会遇到同样的问题:

In上面的代码,我用数组覆盖了$ this-> Auth。解决方案:

$this->Auth->loginAction = array(
       "intranet" => true, 
       "controller" => "employees", 
       "action" => "login" 
      ); 
      $this->Auth->authenticate = array(AuthComponent::ALL => array("userModel" => "Employee")); 
+0

刚发布我的评论后发现错误。很高兴你找到了它,但容易忽略,没有什么可羞耻的! – thaJeztah 2013-03-17 22:03:20

相关问题