【问题标题】:How to change cakephp auth component controller?如何更改 cakephp auth 组件控制器?
【发布时间】:2014-10-29 09:51:44
【问题描述】:

这里我的控制器名称是 AucUsersController。使用 auth 组件后,它正在寻找 userscontroller。我想更改此目录。我尝试了下面的代码,但它不起作用。

public $components = array('Paginator'=>array('limit'=>2),'Auth'=>array(
            'Controller'=>'AucUsers',
            'loginRedirect' => array('controller' => 'aucusers','action' => 'index'),
            'logoutRedirect' => array('controller' => 'aucusers','action' => 'index'),
            'authError'=>'You can not access this page!!',
));

如何更改此默认控制器?

【问题讨论】:

  • 您是否从文档book.cakephp.org/2.0/en/core-libraries/components/… 中阅读了此内容;您不创建控制器。您创建一个 Auth 组件
  • 在appcontroller中添加auth组件后,默认在userscontroller中搜索登录动作。但是这里我使用的是AucUsersController,所以没有任何UsersController。在appcontroller中添加Auth组件后,现在它正在搜索userscontroller .但我没有任何用户控制器。
  • 对不起。我以为你想制作自己的身份验证组件。
  • 您需要在 Auth 设置中更改 loginAction,它是默认用户控制器登录操作
  • 你能告诉我如何改变它吗? @阿布舍克

标签: cakephp cakephp-2.4


【解决方案1】:

CakePHP 默认使用 users/login 进行 loginAction, loginAction 是你定义控制器的属性和 cake 登录的动作

public $components = array('Paginator'=>array('limit'=>2),'Auth'=>array(
            'loginAction' => array(
            'controller' => 'aucusers',
            'action' => 'login'
        ),
            'loginRedirect' => array('controller' => 'aucusers','action' => 'index'),
            'logoutRedirect' => array('controller' => 'aucusers','action' => 'index'),
            'authError'=>'You can not access this page!!',
));

loginRedirect - 它表示用户在登录后应该重定向到的位置 logoutRedirect - 它表示用户在注销后应该重定向到的位置

【讨论】:

    【解决方案2】:

    我相信如果您想更改默认控制器,您必须设置UserModel 选项。我将它设置为 beforeFilter 方法。所以在你的情况下,它会是。

    /**
     * beforeFilter method
     * 
     * @return void
     */
    public function beforeFilter() {
        $this->Auth->authenticate = array(
            'Form' => array(
                'userModel' => 'AucUser',
            )
        );
    
        return parent::beforeFilter();      
    }
    

    我在文档中没有看到有任何控制器选项。

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2015-06-01
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多