Hi all,
I have a problem here:
Filter after sorting at GridView cause problems.
I have two models:
Product: id, title, img, category_id
ProductCategory: id, alias, name, parent.
The relation of them is declared at:
class Product extends CActiveRecord
{
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'category' => array(self::BELONGS_TO, 'ProductCategory', 'category_id'),
);
}
At the Product admin page, I have the following code:
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'pager'=>array(
'header'=>'',
'firstPageLabel'=>'<<',
'prevPageLabel'=>'<',
'nextPageLabel'=>'>',
'lastPageLabel'=>'>>',
),
'columns'=>array(
'id',
'title',
'img',
array(
'name'=>'category_id',
'value'=>'$data->category->name',
'filter'=>CHtml::listData(ProductCategory::model()->findAll(), 'id', 'name'),
'htmlOptions'=>array('width'=>'90px'),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
So that this page will have four columns and the last one will display corresponding product’s category name, and its filter it’s a dropdown list.
Select the dropdown list to filter, it works perfect. I see the request url is:
But, if following :
-
Select category dropdown list to filter
-
click other column (for instance id) to sort
-
Then select category dropdown list to filter again.
It will cause problems:
htmlspecialchars() expects parameter 1 to be string, array given
at CHtml.php
public static function encode($text)
65 {
66 return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset);
67 }
I saw the request URL at this time is:
Why it will generate such request at this situation, How can I avoid this if I want use dropdown filter for gridview column. Am I miss anything at Product / ProductCategory model or their controlers?
I would highly appreciate if someone can help me -).
Thanks.