Home > Backend Development > PHP Tutorial > Yii框架在首页已登录,在其他页面检测不出登录

Yii框架在首页已登录,在其他页面检测不出登录

WBOY
Release: 2016-06-23 13:43:57
Original
863 people have browsed it

if(Yii::app()->user->getIsGuest()){
$blog_model=new Blog();
$blog_model->content=$_POST['content'];  
$blog_model->title=$_POST['title'];
date_default_timezone_set('UTC');
$blog_model->time=date("Y-m-d H:i:s");

if($blog_model->save()){
$this->redirect(SITE_URL.'blog/index');
//$this->renderPartial('success');
}
}else{
$this->renderPartial('error');
}

这是在博客界面,判断是否登录,登录就允许发帖,但是总是说我没有登录,实际上已经登录,求解决办法


回复讨论(解决方案)

session是自动开启的吗,获取打印一下看看

if(Yii::app()->user->getIsGuest()){
$blog_model=new Blog();
$blog_model->content=$_POST['content'];  
$blog_model->title=$_POST['title'];
date_default_timezone_set('UTC');
$blog_model->time=date("Y-m-d H:i:s");

if($blog_model->save()){
$this->redirect(SITE_URL.'blog/index');
//$this->renderPartial('success');
}
}else{
$this->renderPartial('error');
}

这是在博客界面,判断是否登录,登录就允许发帖,但是总是说我没有登录,实际上已经登录,求解决办法


Yii::app()->user->getIsGuest这段代码意思是 如果用户是游客。。。


if(Yii::app()->user->getIsGuest()){
$blog_model=new Blog();
$blog_model->content=$_POST['content'];  
$blog_model->title=$_POST['title'];
date_default_timezone_set('UTC');
$blog_model->time=date("Y-m-d H:i:s");

if($blog_model->save()){
$this->redirect(SITE_URL.'blog/index');
//$this->renderPartial('success');
}
}else{
$this->renderPartial('error');
}

这是在博客界面,判断是否登录,登录就允许发帖,但是总是说我没有登录,实际上已经登录,求解决办法


Yii::app()->user->getIsGuest这段代码意思是 如果用户是游客。。。

我知道了。。瞬间感觉自己傻爆了。。
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template