Yii Framework Forum: how to access session globally in web application - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to access session globally in web application Rate Topic: -----

#1 User is offline   Sagar88 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 02-March 12

Posted 13 April 2012 - 11:13 AM

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

Attached File(s)


0

#2 User is offline   Ivica 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 317
  • Joined: 25-May 11

Posted 14 April 2012 - 01:49 AM

I don't see that you created session anywhere in SiteController.php file
Zurmo: Yii Powered Open Source CRM
zurmo.org
0

#3 User is offline   Sagar88 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 02-March 12

Posted 16 April 2012 - 02:16 PM

View PostIvica, on 14 April 2012 - 01:49 AM, said:

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),

--------------------------
0

#4 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 07 June 2012 - 02:34 AM

@Sagar,
You can use Yii session as,

Yii::app()->session['xyz'] = "value";

and can use anywhere in site as,

echo Yii::app()->session['xyz'];
Thanks,
Kiran Sharma.
2

#5 User is offline   Latha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 17-June 13

Posted 21 June 2013 - 05:56 AM

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.
0

#6 User is offline   Latha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 17-June 13

Posted 21 June 2013 - 06:14 AM

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users