Strange Problem with Yii CGridView Ajax URL

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.

Can somebody try !!

please i need a screen dump your view code and your config/main.php

I have provided the view code. Its just this cgridview. And what do you need from my main.php. Which parts?

Has anyone every answered this problem. I actually have had the problem for a day and half. The only difference betweens I have are that I do not use filter, I use the advanced search style from gii, with the exception of yiiJsonGridView.

To add I also noticed a problem with pagination url in that they do not create utf-8 encoded urls by default. I get url errors when dates are in m/d/y format(caused by the /).

I did notice that if I turn off the url manager everything works great.

If someone has a solution that would be great, I would love to post my code, but am not sure if I am allowed to.

I had the same problem too. Temporary ‘solve’ it by setting ajaxUpdate=false




$this->widget('zii.widgets.grid.CGridView', array(

       'dataProvider' => $model->search(),

        'filter' => $model,

	'ajaxUpdate'=>false,



Try use the property "ajaxtype" is "POST"




$this->widget('zii.widgets.grid.CGridView', array(

    ..........

    'ajaxtype'=>'POST',

    ''''''''''

));



1 Like