Home >Backend Development >PHP Tutorial > 懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent:user('id')取不到值,该怎么解决

懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent:user('id')取不到值,该怎么解决

WBOY
WBOYOriginal
2016-06-13 13:28:21861browse

懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent::user('id')取不到值

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->function login(){
        if(empty($this->request->data['User']['username']) or empty($this->request->data['User']['password'])){
            $this->Session->setFlash('Please intyped a valied account!');
        }elseif ($this->Auth->login($this->request->data['User'])) {
            $this->User->id= AuthComponent::user('id');
            $this->redirect("/users/index");    
        }
        else{                
                $this->redirect("/users/logout");    
            }    
        }


------解决方案--------------------
没放到session里面
------解决方案--------------------
一般是这样去获取用户的信息的
$this->Auth->user();
自己试下,
我的用法是这样
1.在AppController中beforeFilter中设置$this->Auth相关属性
2.在UsersController中
function login(){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}
///.....
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn