cgridview pagination issue

hello sir,

I have trouble about cgridview pagination.

I am using admin page(/{module}/admin that) generated by gii.

it has search form and grid with pagination. its work well without urlmanager

but my team have create urlmanager rule long ago.




'urlManager'=>array(

        'urlFormat'=>'path',

        'showScriptName'=>false,

	'rules'=>array(

	'<controller:\w+>/<id:\d+>'=>'<controller>/view',

	'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

	'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',


	'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',


	),

),



when I use admin page with this urlmanager rule. It has some problem.

  • if not using grid sort or pagination. I can filter in grid and form.

  • but if using sort or pagination. I can not filtering in grid and form anymore.

page link is wierd and i think because of some attribute(params) are null like this

/{module}/{controller}/admin/BookManageMain%5Bbmm_code%5D//BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid

if I am copy this url to another tab and Its can not filtering in grid and form too.

but if I remove attribute that has null value(BookManageMain%5Bbmm_code%5D//) I can filter grid and form.

/{module}/{controller}/admin/BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid

console log (not sure filter use POST and sort/page use GET)




before click pagerlink or sorting

.../{controller}/action?BookManageMain%5Bbmm_code%5D=&BookManageMain%5Bbmm_tid%5D=2&...&BookManageMain_page=1&ajax=book-manage-main-grid


after click


.../{controller}/action/BookManageMain%5Bbmm_code%5D//BookManageMain%5Bbmm_tid%5D/2/.../BookManageMain_page/2/ajax/book-manage-main-grid



i am confuse where and how to solve the problem(can not change urlmanager. its affect a whole site ).

  1. remove attribute with null value by edit some yii core class(clinkpager, cpagination, cbaseurl or etc.)

  2. create some controller action or model method to deal with.

thanks for you help(my english is poor Sorry :rolleyes: )

Hi adzpire, welcome to the forum.

It’s a bit complicated issue, but the easiest ways to solve it is to modify your url manager settings. (I know that you don’t want to.)




'urlManager'=>array(

    'urlFormat'=>'path',

    'showScriptName'=>false,

    'appendParams' => false, // add this

    'rules'=>array(

        '<controller:\w+>/<id:\d+>'=>'<controller>/view',

        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

        '<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',

    ),

),



Or, alternatively:




'urlManager'=>array(

    'urlFormat'=>'path',

    'showScriptName'=>false,

    'rules'=>array(

        '<controller:\w+>/<id:\d+>'=>'<controller>/view',

        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

        '<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',

        '<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>', // add this

    ),

),



These settings will make the search/sort/paging parameters to be in the query string instead of path info in the requested url. I mean,

not "{module}/{controller}/action/BookManageMain%5Bbmm_code%5D//BookManageMain%5Bbmm_tid%5D/2/…"

but "{module}/{controller}/action?BookManageMain%5Bbmm_code%5D=&BookManageMain%5Bbmm_tid%5D=2&…"

And CGridView seems to expect those parameters to be in the query sting when doing ajax filtering. The sorting and paginating seem to work fine with the path info format, but the filtering will not. So just removing empty parameters from the path info will not solve the problem.

As for the change in the url manager settings, I don’t think it will break the existing pages.

many thanks. sir softark :)