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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:28:21
Original
909 people have browsed it

懂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");    
            }    
        }
Copy after login


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

Related labels:
Statement of this Website
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
Latest Issues
Why is this ID written like this?
From 1970-01-01 08:00:00
0
0
0
Small question about $this
From 1970-01-01 08:00:00
0
0
0
javascript - es6中this
From 1970-01-01 08:00:00
0
0
0
This file demo.mp4
From 1970-01-01 08:00:00
0
0
0
What's the use of this?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template