开发者

CakePHP log in system

开发者 https://www.devze.com 2023-03-12 16:31 出处:网络
I am editing a website which someone has made in CakePHP, but I don\'t have any previous experience in Cake. I\'m reading the manual but finding it quite hard to understand so thought I would post a q

I am editing a website which someone has made in CakePHP, but I don't have any previous experience in Cake. I'm reading the manual but finding it quite hard to understand so thought I would post a question on here to see if I can get any quick answers.

I think that this code is being used to display a login box, and you can only log in with username test and password 123123

var $components = array("Auth", "Acl");

function beforeFilter(){
    $this->Security->loginOptions = array(
    'type' => 'basic',
    'realm' => 'Authenticate Emergency Response Center'
);
$this->Security->loginCredentials = array(
    'test' => '123123'
);
$this->Security->requireLogin();
    $this->_bindToSite();
    p开发者_JAVA百科arent::beforeFilter(); 
}

I want the log in box to appear still, but I want to fill the loginCredentials array automatically with information from the database. I have a table called 'operators' which contains the fields 'user_id' and 'password'.

Could someone tell me how I would alter the code above to allow any of the usernames/passwords stored in the operators table to log in?

Thanks for any help


Build an array from the database and set $this->Security->loginCredentials equal to your array.


You can leave most of the hard work up to CakePHP's Auth component, but if you want to use a model other than the default 'User', you'll just need to set this in beforeFilter(). The best place to do this is probably app_controller.php in your app\ directory.

function beforeFilter(){
    $this->Auth->userModel = 'Operator';
    $this->Auth->fields = array(
        'username' => 'user_id', 
        'password' => 'password'
    );
);
0

精彩评论

暂无评论...
验证码 换一张
取 消