CakePHP登录和会话管理

时间:2011-07-29 16:10:07

标签: session cakephp login

我正在使用CakePHP启动项目,我正在尝试了解登录过程,然后创建一个包含登录/用户字段的会话:

function login_php(){
    // -=> Retrieve form fields "u" and "p" (Username and password):
    $a = $this->params['form']['u']; //email address.
    $b = $this->params['form']['p']; //password.

    // -=> Query Retrieve User, match email and password fields:
    // -=> Make users data available in the view:
    $this->set('users', $this->User->find('all', array('conditions' => array('User.email =' => $a , 'User.password =' => $b))));
}

此时我想从用户字段创建一些会话变量并在会话中设置它们:

    //Setting Session Variables:
    $this -> Session -> write( "name", $users['User']['fname'] . " " . $users['User']['lname']);

    //Retrieving Session Variables:
    echo $this -> Session -> read("name");

但是我在设置会话变量的最后一部分时遇到了麻烦。

问题:

如何为用户设置会话变量?

任何帮助赞赏的人......

1 个答案:

答案 0 :(得分:3)

你知道蛋糕附带了一个认证模块,是吗?

http://book.cakephp.org/view/1250/Authentication