HI everybody,
I am new in Yii framework,I am unable to access session globally in my web application i mean if i create session in site controller then i can access the session in same controller but i am unable to access session in different controller, Please help me
ivica
(Ivica Nedeljkovic)
April 14, 2012, 6:49am
2
I don’t see that you created session anywhere in SiteController.php file
sorry i didn’t provided complete details
i have created session in useridentity
private $_id;
public function authenticate()
{
$users=Agent::model()->findByAttributes(array('A_username'=>$this->username));
if($users===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else
{
if($users->A_password!==$this->password)
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else
{
$this->_id = $users->A_id;
$session=new CHttpSession;//modified
$session->open();
$session['name']=$this->username;//modified
$this->errorCode=self::ERROR_NONE;
}
}
return !$this->errorCode;
}
by the way problem has been resolved now i am able to access session
public function accessRules()
{
$name;
$session=new CHttpSession;//modified
$session->open();
if(isset($session['name']))
{
$name = $session['name'];
}
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
//'users'=>array($session['name']),
'users'=>array($name),
kiran123
(Sharmakiran71)
June 7, 2012, 7:34am
4
@Sagar ,
You can use Yii session as,
Yii::app()->session[‘xyz’] = “value”;
and can use anywhere in site as,
echo Yii::app()->session[‘xyz’];
Latha
(Lparameshwarappa)
June 21, 2013, 10:56am
5
hi can anybody let me know how to display username of session once user login, in new page created in view/demo/ and i should insert in database if he create product.
Latha
(Lparameshwarappa)
June 21, 2013, 11:14am
6
got username but help me to insert his name into db along with the product he z adding., product z adding but hw to add username?