如何将一个新注册用户设置为已登录状态? [ 新手入门 ]
如下代码:???号处的应该如何赋值呢?
public function actionCreate() {
$model = new Users('create');
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if (isset($_POST['Users'])) {
$model->attributes = $_POST['Users'];
$model->pwd=md5($model->pwd);//将密码加密后存储
$model->pwd2=md5($model->pwd2);
if ($model->save())
yii::app()->user->username=$model->username;//???
yii::app()->user->id=$model->id;//???
Yii::app()->user->setState('identity','user');//设为已登录
$this->redirect(array('site/index'));
}
$this->render('create', array(
'model' => $model,
));
}
共 2 条回复
-
lz19881123 回复于 2012-01-06 13:40 举报
if(Yii::app()->user->isGuest) echo CHtml::link('登录',array('userss/login')); else echo CHtml::link('注销('.Yii::app()->user->name.')',array('userss/logout'));
webyjh
注册时间:2011-12-12
最后登录:2016-10-06
在线时长:1小时45分
最后登录:2016-10-06
在线时长:1小时45分
- 粉丝2
- 金钱1090
- 威望0
- 积分1100