Dear Friend
We can make the all the GET parameters stateful by storing them in session.
Then we can make use of it at any place.
I have a model Post.
PostController.php
public function actionAdmin()
{
$model=new Post('search');
$model->unsetAttributes();
if(isset($_GET['Post'])){
$model->attributes=$_GET['Post'];
}
Yii::app()->user->setState("grid",$_GET);//storing all the GET parameters in session.
$this->render('admin',array(
'model'=>$model,
));
}
//For an example ,Now we can make use of it in actionIndex
public function actionIndex()
{ $sort="";
if(Yii::app()->user->hasState("grid"))
{
$grid=Yii::app()->user->getState('grid');
if(isset($grid["Post_sort"]))
{
$sort=$grid['Post_sort'];
$dot=strpos($sort,'.');
if($dot>0)
{
$prop=substr($sort,0,$dot);
$order=substr($sort,$dot+1);
$order=strtoupper($order);
$sort=$prop." ".$order;
}
}
Yii::app()->user->setState('grid',null);
}
$dataProvider=new CActiveDataProvider('Post',array(
'sort'=>array('defaultOrder'=>$sort),
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
Rather than strong in session, if you want a link with get parameter the following can be done.
You have to declare beforeAjaxUpdate property in CGridView.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'post-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'beforeAjaxUpdate'=>'js:function(id,options)
{
var url=options.url;
var arr=url.split("&");
arr.shift();
var params={};
for each(var e in arr)
{
var el=e.split("=");
params[el[0]]=el[1];
}
$("#link").attr("href","index.php?r=post/index"+"&"+params.Post_sort);
}',
'columns'=>array(
'id',
'title',
'created',
...............................................................................
..............................................................................
Then we have to add a link in following way.
echo CHtml::link("index","#",array('id'=>'link'));
I hope I helped a bit.