I’m trying to implement a certain persistent data that belongs to a specific user according to the cookbook page of How to add more information to Yii::app()->user.
Let us assume that the Yii::app()-user has the flag authenticateMode.
It is set in the `protected/components/UserIdentity.php' as the cookbook says:
<?php
:
public function authenticate()
{
:
if ($user===null) {
if (isset(Yii::app()->user->authenticateMode) && Yii::app()->user->authenticateMode == self::REGISTRATION) {
(1)
} else {
$this->setState('authenticateMode', self::REGISTRATION);
(2)
}
Obviously, since it is a persistent data, I should not initialize this flag. I wanted to do (2) first, then (1) next time according to this flag.
Then, I got a following error.
Quote
Description
Property "CWebUser.authenticateMode" is not defined.
Source File
/var/www/html/yii/framework/web/auth/CWebUser.php(88)
00076: /**
00077: * PHP magic method.
00078: * This method is overriden so that persistent states can be accessed like properties.
00079: * @param string property name
00080: * @return mixed property value
00081: * @since 1.0.3
00082: */
00083: public function __get($name)
00084: {
00085: if($this->hasState($name))
00086: return $this->getState($name);
00087: else
00088: return parent::__get($name);
00089: }
00090:
00091: /**
00092: * PHP magic method.
00093: * This method is overriden so that persistent states can be set like properties.
00094: * @param string property name
00095: * @param mixed property value
00096: * @since 1.0.3
00097: */
00098: public function __set($name,$value)
00099: {
00100: if($this->hasState($name))
Stack Trace
#0 /var/www/html/yii/framework/web/auth/CWebUser.php(88): CComponent->__get('authenticateMod…')
#1 /var/www/html/yii/demos/test/protected/components/UserLogin.php(19): CWebUser->__get('authenticateMod…')
The code of the portlet of 'UserLogin' is as follows.
<?php
class UserLogin extends Portlet
{
const AUTHENTICATION=0;
const REGISTRATION=1;
public $title='Login';
protected function renderContent()
{
$form=new LoginForm;
if(isset($_POST['LoginForm']))
{
$form->attributes=$_POST['LoginForm'];
if($form->validate('login'))
$this->controller->refresh();
}
exception --> if (Yii::app()->user->authenticateMode == self::AUTHENTICATION)
$this->render('userLogin',array('form'=>$form));
else
$this->render('userLoginReg',array('form'=>$form));
}
}
How do I use this persistent data without initializing it?