bleu
(Zend W)
October 11, 2011, 8:02am
1
My Controller code after getting post items
$dataProvider=new CActiveDataProvider('Post', array(
'criteria'=>array(
'condition'=>'status='.$_POST['Details']['status'];,
'order'=>'create_time DESC',
'with'=>array('author'),
),
'pagination'=>array(
'pageSize'=>20,
),
));
Now I get the result view in which the first page shows the results, but when I go to the second page it gives me errors, because it shows the the query is run but
status=
shows as blank I believe in the first instance it takes status as 1 or 2(ie
where status=1
) but when I go to the 2nd page the post data is not found.
How can I solve this?
mdomba
(Maurizio Domba Cerin)
October 11, 2011, 8:28am
2
When you get to the second page a new request to the server is made and at that time $_POST[‘Details’][‘status’] is empty as this value is not POSTed…
One solution would be to save this value in the session the first time it is posted… and then read it from the session… for this you can use setState() - http://www.yiiframework.com/doc/api/1.1/CWebUser#setState-detail
bleu
(Zend W)
October 11, 2011, 12:14pm
3
mdomba:
When you get to the second page a new request to the server is made and at that time $_POST[‘Details’][‘status’] is empty as this value is not POSTed…
One solution would be to save this value in the session the first time it is posted… and then read it from the session… for this you can use setState() - http://www.yiiframework.com/doc/api/1.1/CWebUser#setState-detail
I have gone through setState() - http://www.yiiframework.com/doc/api/1.1/CWebUser#setState-detail but have not been able to apply it , an example or somewhere where it is implemented would be good
I am trying to use it like below, but whenever I go to the form again and try to post it takes the old values
$session=new CHttpSession;
$session->open();
if(empty($session['status'])){
$session['status']=$_POST['Details']['status'];
}
$dataProvider=new CActiveDataProvider('Post', array(
'criteria'=>array(
'condition'=>'status='.$session['status'];,
'order'=>'create_time DESC',
'with'=>array('author'),
),
'pagination'=>array(
'pageSize'=>20,
),
));
mdomba
(Maurizio Domba Cerin)
October 11, 2011, 1:18pm
4
You can use it like
Yii::app()->user->setState('status', <yourvalue>);
Note that in your code you are testing if the session is already set… but you are not testing if the POST variable has the value you need
bleu
(Zend W)
October 12, 2011, 4:48pm
5
mdomba:
You can use it like
Yii::app()->user->setState('status', <yourvalue>);
Note that in your code you are testing if the session is already set… but you are not testing if the POST variable has the value you need
Thanks now I am setting the session variables when there is a post, which is not giving me any errors for right now
i.e
if($post){session variables set}
Hope it helps anybody with a similar problem