/**
* Returns a value indicating whether the user is a guest (not authenticated).
* @return boolean whether the current application user is a guest.
*/
public function getIsGuest()
{
return $this->getState('__id')===null;
}
from class CWebUser have a return i couldn’t understand
why ===null as $this->getState(’__id’) will return either a value or a null result?
When a user is logging in, a call to changeIdentity made. This method saves the id of the user (by default, but can be changed) into session storage.
/**
* Changes the current user with the specified identity information.
* This method is called by {@link login} and {@link restoreFromCookie}
* when the current user needs to be populated with the corresponding
* identity information. Derived classes may override this method
* by retrieving additional user-related information. Make sure the
* parent implementation is called first.
* @param mixed $id a unique identifier for the user
* @param string $name the display name for the user
* @param array $states identity states
*/
protected function changeIdentity($id,$name,$states)
{
Yii::app()->getSession()->regenerateID();
$this->setId($id);
$this->setName($name);
$this->loadIdentityStates($states);
}
The usual way to
access logged in user information is to call Yii::app()->user->getState(‘fieldname’) and to
store info in the session call Yii::app()->user->setState(‘fieldname’, ‘fieldvalue’).
This information is usually set when the user is logging in (and has been verified). Usually, we want to store non private fields that can be accessed later without making a DB call (username, fullname, preferences etc)
That way, when you call getState(’__id’) on a non logged in user, NULL is returned.