首页 >后端开发 >php教程 >懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent:user('id')取不到值,该怎么解决

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

WBOY
WBOY原创
2016-06-13 10:26:46896浏览

懂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());
}
///.....
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn