当前位置:Gxlcms >
PHP教程 >
懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent:user('id')取不到值,该怎么解决
懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent:user('id')取不到值,该怎么解决
时间:2021-07-01 10:21:17
帮助过:5人阅读
懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent::user('id')取不到值
PHP code
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());
}
///.....
}