CGridView filters and urlFormat = path

I have an ongoing project. It is currently live and works using SEF URLs with the following config:




'urlManager'=>array( 

  'urlFormat'=>'path',

  'showScriptName'=>false,

  'rules'=>array(

    ...

  ),

),

I am currently attempting to implement some admin functions, one of which is management of keywords to which the CGridView widget seems perfectly matched. So, I have created an action in my admin controller:


  public function actionKeywords()

  {

    $dataProvider = new CActiveDataProvider('Keyword');

    $model = new Keyword();

    $this->render('keywords', array('model'=>$model,'dataProvider'=>$dataProvider));

  }

and the matching view:


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

  'dataProvider'=>$dataProvider,

  'filter'=>$model,

  'columns'=>array(

    'id',

    'keyword',

    'description',

    'type_id',

    'create_time',

    'ignored',

  ),

));

I realise the filter will not really work yet as I am not assigning the $model->search() function as the dataProvider, however that raises a separate issue so I’ll deal with that later.

Whenever I enter a value in the filter fields, the table is updated with an ajax request like:


http://mydomain.com/admin/keywords?Keyword[id]=&Keyword[keyword]=&Keyword[synonym]=&Keyword[description]=&Keyword[type_id]=&Keyword[create_time]=&Keyword[ignored]=1&ajax=yw0

It seems that these GET variables are not being read by the Yii application, as adding a trace to the action like so:


Yii::trace("GET PARAMS: ".print_r($_GET,true));

shows up in Firebug with


[10:14:22.457][trace][application] GET PARAMS: Array ( ) 

Am I missing something? I know I can edit jquery.yiiGridView.js to use POST instead of GET, but I’d rather not edit core framework. I thought Yii was supposed to handle get queries in the URL; or is it something with my rewrite?

M Wotton, same issue here, running PHP 5.3+, Ubuntu 9.10, nginx, and Yii trunk.

Dumping out $_SERVER shows that $_SERVER[‘REQUEST_URI’] does indeed have the full URL stored (including the GET params), but Yii doesn’t appear to be parsing the GET when using the PATH url format.

Changing the system to use POST instead of GET doesn’t solve the root issue, which appears to be how Yii handles GET requests in a PATH rewrite routine.

Ticket created, patch submitted: http://code.google.com/p/yii/issues/detail?id=1170&sort=-id&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Stars%20Summary

Turns out it’s a rewrite issue, query string isn’t being passed into Yii.

Post your rewrite rules if you’d like assistance.

I was having the same issues until I added the rewrite rule in my nginx configuration pointed by intel352:




if (!-e $request_filename) {    

	rewrite  ^(.*)$  /index.php  last;    

	break;

}



Thanks for the tip!

Improved Nginx rewrite config for Yii:





location ~ /(protected|framework|nbproject) {

    deny all;

    access_log off;

    log_not_found off;

}


location ~ /themes/\w+/views {

    deny all;

    access_log off;

    log_not_found off;

}


location / {

    try_files $uri $uri/ /index.php?$args;

}