Hi All,
I have recently started to work with Yii and have been quite impressed with it. However, i am facing a strange issue with regards to how Ajax URLs are created for CGridView. What i am trying is searching for the first time, then going some pages ahead in the search results by clicking on the pagination links and then searching again. However the second time my grid is sending request in the following format
127.0.0.1/myapp/backend/customers/index/XDEBUG_SESSION_START/1/Accounts%5BaccountID%5D//Accounts%5Bname%5D//Accounts%5Baddress%5D/address+1/Accounts%5Bbirthday%5D//Accounts%5BclientType%5D//Accounts%5Bemail%5D//Accounts%5Bbalance%5D//Accounts%5BhasAccess%5D//Accounts_page/3/ajax/yw1?ajax=yw1&Accounts%5BaccountID%5D=&Accounts%5Bname%5D=&Accounts%5Baddress%5D=&Accounts%5Bbirthday%5D=&Accounts%5BclientType%5D=&Accounts%5Bemail%5D=&Accounts%5Bbalance%5D=&Accounts%5BhasAccess%5D=&Accounts_page=1
(omitted http as i am not allowed to embed links right now. The url starts with http though).
you can see half of this URL is Re-written (which is created by CPagination when rendering pagination links). However, Yii’s gridview js appends the new query to pagination link ending up with duplication of variables in URL with both previous and new value. As a result of this, when the code execution reaches Line 411 in the CUrlManager.php which is
$_REQUEST[$name]=$_GET[$name]=$value;
the value in $_GET variable are lost ($value contain old values of the url which are contained in the rewritten part of the URL (SEO Friendly)). And I end up with previous search results again.
The Rules that i am using
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'<module:\w+>/<controller:\w+>/<action:\w+>"=>"<module>/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName' => false,
'caseSensitive' => true,
),
My view file :
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array (
'name' => 'accountID',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array(
'name' => 'name',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array(
'name' => 'address',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array( // display 'create_time' using an expression
'name'=>'birthday',
'value'=>'date("M j, Y", strtotime($data->birthday))',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array(
'name' => 'clientType',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array(
'name' => 'email',
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
array(
'name' => 'balance',
'type' => 'raw',
'header' => 'Balance',
'value' =>'($this->grid->owner->widget("application.extensions.jeditable.DsJEditableWidget", array(
"model" => $this->grid->dataProvider,
"name" => "balance_".$data->accountID,
"value" => $data->balance,
"jeditable_type" => "text",
),true))',
),
array( //
'class' => 'JToggleColumn',
'name' => 'hasAccess',
'filter' => array(1=>'Yes', 0=>'No'),
'checkedButtonImageUrl'=> Yii::App()->baseUrl.'/images/checked.png', // checked image
'uncheckedButtonImageUrl'=> Yii::App()->baseUrl.'/images/unchecked.png', // unchecked image
'checkedButtonLabel'=>'Yes', // tooltip
'uncheckedButtonLabel'=>'No', // tooltip
'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
),
)
)
I dont want to use
'ajaxUrl' => $this->createUrl('index')
as it resets my search and pagination when i try to use jtogglecolumn, due to absence of query data in request url.