我使用的是Yii 1.1.15框架。
我无法搜索&作为查询字符串中属性(例如brand_name)中的符号。如果我输入&URL的符号如下:
localhost/doctors/brand/?brand[brand_name]=&&brand[brand_status]=
这里的情况是brand[brand_name]=&
。它不考虑&
,并被视为下一个参数终止,如果我只是对该字符进行编码,它将变为:%26
,因此url将变为localhost/doctors/brand/?brand[brand_name]=%26&brand[brand_status]=
,并给出正确的结果。
但是如何对yii CGridView过滤文本数据进行编码呢?
提前谢谢。
CGridView
使用GET作为默认的ajax类型,&
是http请求的GET参数的分隔符,因此不能将此字符用作搜索字符串的一部分。我认为解决方案是对ajax请求使用POST而不是GET。要将CGridView ajax参数从GET更改为POST,请将'ajaxType' => "POST"
添加到您的CGridView选项中:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'...',
'ajaxType' => "POST",
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
...
),
)); ?>