【问题标题】:authentication using a different table and column使用不同的表和列进行身份验证
【发布时间】:2016-01-21 05:46:05
【问题描述】:

如何在 cakephp 中更改用户表名和列名以进行身份​​验证。默认情况下,它以用户为表名。

class AppController extends Controller {

    public $components = array(
        'Session','Security',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'project', 'action' => 'index', 'Project Details'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
        )
    );



    function beforeFilter() {
        $this->Auth->allow('login');

    }
}

型号:

  App::uses('AppModel', 'Model');
    class Users extends AppModel {
    var $useTable = 'manager';


    } 

【问题讨论】:

    标签: cakephp cakephp-2.0 cakephp-3.0 cakephp-2.3 cakephp-2.1


    【解决方案1】:

    在 AppController 的 beforeFilter() 方法中添加以下代码

    function beforeFilter(){
       parent::beforeFilter();
       $this->Auth->authenticate = array(
       AuthComponent::ALL => array("fields" => array("username" => "your_username_column", "password" => "your_password_column") )
    

    ); }

    【讨论】:

    • 如何获取登录用户名和用户名
    • $this->Auth->user('id'); $this->Auth->user('用户名');
    猜你喜欢
    • 2021-10-06
    • 2013-06-28
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    相关资源
    最近更新 更多