使用不同的表和列

时间:2016-01-21 05:46:06

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

如何在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';


    } 

1 个答案:

答案 0 :(得分:0)

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

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

);     }