hi…
I am storing a session data in my controller for selecting category…
$categorySelected = $_GET['select_user'];
Yii::app()->session['category'] = $categorySelected;
switch (Yii::app()->session['category'])
{
case 'patient':
$this->render('patient');
break;
then I am trying to use this session variable to the view pages for automatic display of category information like…
<div class="row">
<?php echo $form->labelEx($model,'category'); ?>
<?php echo $form->textField($model,'category',array('size'=>20,'value'=> Yii::app()->session['category'], 'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'category'); ?>
</div>
but i am not getting any value in the category textfield…
plz help
if anybody have any idea how to solve this problem plz reply…
mdomba
(Maurizio Domba Cerin)
February 9, 2011, 8:30am
3
If you don’t get any value it can mean that $_GET[‘select_user’] is null
You can check this simply by trying to use this line
Yii::app()->session['category'] = 'sometext';
and you will see if that text will be in the textfield…
Anyway… in the view… instead of using htmlOption[‘value’] you can assign that value to the model field before the call to textField… like:
$model->category=Yii::app()->session['category'];
mdomba:
If you don’t get any value it can mean that $_GET[‘select_user’] is null
You can check this simply by trying to use this line
Yii::app()->session['category'] = 'sometext';
and you will see if that text will be in the textfield…
Anyway… in the view… instead of using htmlOption[‘value’] you can assign that value to the model field before the call to textField… like:
$model->category=Yii::app()->session['category'];
thanks mdomba for your reply but
$_GET['select_user']
is not null I am able to access the session data on the same page but when i am accessing it in my view page to display the selected category that time i am not getting any value?
twisted1919
(Serban Cristian)
February 10, 2011, 10:19pm
5
Why don’t you just write the “category” property of the model, something like:
$categorySelected = $_GET['select_user'];
$model=new WhateverModel;
$model->category=$categorySelected ;
switch ($categorySelected)
{
case 'patient':
$this->render('patient');
break;
Then in the view, just:
<div class="row">
<?php echo $form->labelEx($model,'category'); ?>
<?php echo $form->textField($model,'category',array('size'=>20, 'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'category'); ?>
</div>
Yes that would be an option but the actual scenario is little different. I am showing the category in the registration page and according to the category selected in the first page the registration form and rest of the page differs in view. So i think can’t set the category in the model before user registration.
mdomba
(Maurizio Domba Cerin)
February 11, 2011, 7:48am
7
Could be something with the PHP settings about session handling…
Here is a little script to test if session is working… copy/paste it to a file "page1.php"… everytime you click the link the views output should be incremented…
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
echo '<p><a href="page1.php">Refresh</a></p>';
?>
If this is not working you need to check the session save path that it points to an existing folder…
mdomba:
Could be something with the PHP settings about session handling…
Here is a little script to test if session is working… copy/paste it to a file "page1.php"… everytime you click the link the views output should be incremented…
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
echo '<p><a href="page1.php">Refresh</a></p>';
?>
If this is not working you need to check the session save path that it points to an existing folder…
Thank you for the code
The above is working for me
views = 22
Refresh
I think there might be some other problem
weavora
(Yury Tolochko)
February 11, 2011, 2:16pm
10
Maybe you should try to use:
Yii::app()->user->setState(‘category’,$category) for category saving
Yii::app()->user->getState(‘category’) for category getting
I really don’t know if it would solve your problem, but you could try
rknalajala
(Ramakrishnanalajala)
June 10, 2011, 5:02am
11
mdomba:
Could be something with the PHP settings about session handling…
Here is a little script to test if session is working… copy/paste it to a file "page1.php"… everytime you click the link the views output should be incremented…
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
echo '<p><a href="page1.php">Refresh</a></p>';
?>
If this is not working you need to check the session save path that it points to an existing folder…
it is interesting topic on session management in yii.Where can i find page1.php?can you suggest me some good wiki articles on session management.i tried this code for maintaing my session
in config.php i enabled autostart to true in components array.
in useridentity.php i have kept the following code
$session=new CHttpSession;
$session->open();
$session['societyId']=$societyusers->societyid; // set session variable 'name3'
$session['societyName']=$societyusers->societyname;
$this->setState('societyName', $societyusers->societyname);
$session->close();
and in loginform.php i kept code as
Yii::app()->societyusers->getState(societyname);
but when i login its not showing anything do i have to do something more than this.how can i know whether a session is working or not?please guide me
thanks
ramakrishna
mdomba
(Maurizio Domba Cerin)
June 10, 2011, 6:51am
12
This is not a Yii file… you just create a new empty file “page1.php” and put in it the code above… than from the browser you run that file… every time you click the link… the counter should increase… if it’s not increasing you have to check the session configuration in PHP…
As for the articles don’t know what to suggest… just go to the wiki page and search for session…
rknalajala
(Ramakrishnanalajala)
June 10, 2011, 9:14am
13
mdomba:
This is not a Yii file… you just create a new empty file “page1.php” and put in it the code above… than from the browser you run that file… every time you click the link… the counter should increase… if it’s not increasing you have to check the session configuration in PHP…
As for the articles don’t know what to suggest… just go to the wiki page and search for session…
this code is working when i create a file called page1.php and run it from browser.so there is no problem with my session configuration in php.problem is only with my code i think?do i have to enable or set any rules in controller?
gasserol
(Oliver Gasser)
March 9, 2013, 9:56am
14
Thanks Maurizio, this was a great help! after searching for a long while, you gave me the final input… everything works fine now!