Php 在yii中维护一个字段的会话

Php 在yii中维护一个字段的会话,php,yii,Php,Yii,我想在另一个叫做注册模型的模型中使用这个用户名。这行有什么错误 在signp模型中,我使用 Yii::app()->session['uniqueid'] = $this->username;//got error in this line public function authenticate() { $record= User::model()->findByAttributes(array('username'=>$this-&g

我想在另一个叫做注册模型的模型中使用这个用户名。这行有什么错误 在signp模型中,我使用

Yii::app()->session['uniqueid'] = $this->username;//got error in this line

public function authenticate()
    {
            $record= User::model()->findByAttributes(array('username'=>$this->username));
                if($record===null)
                    $this->errorCode=self::ERROR_USERNAME_INVALID;
                else if($record->password!==$this->password)
                    $this->errorCode=self::ERROR_PASSWORD_INVALID;
                else
        {

            $this->errorCode=self::ERROR_NONE;
                    //    $this->setState('group_id', $user->group_id);
                        // Store the role in a session:
                       $this->setState('role', $record->accessrole);
                      // $this->user_id = $record->user_id;

    }

您不能从函数外部调用此分配(
Yii::app()->session['uniqueid']=$this->username;
)。方法内部的传输会话分配。
您还需要确保在类中声明属性
username

分析错误:语法错误、意外的'Yii'(T_字符串)、预期函数(T_函数)在第18行的C:\wamp\www\bid\protected\components\UserIdentity.php中,您是否尝试将其放在构造函数或可调用函数中?您在哪里使用该代码?在注册模型aftersavefunction()中
$id=Yii::app()->session['uniqueid'];