Php 使用Yii对某些字段排序不起作用
我有以下代码 数据提供者:Php 使用Yii对某些字段排序不起作用,php,yii,Php,Yii,我有以下代码 数据提供者: public function search() { $criteria = new CDbCriteria; $criteria->compare('id', $this->id, true); $criteria->compare('firstname', $this->firstname, true); $criteria->compare('lastname', $this->lastnam
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id, true);
$criteria->compare('firstname', $this->firstname, true);
$criteria->compare('lastname', $this->lastname, true);
$criteria->compare('email', $this->email, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 20
),
'sort' => array(
'defaultOrder' => 'id DESC'
)
));
}
GridView:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array('name'=>'id','htmlOptions'=>array( 'width'=>'10%' )),
array('name'=>'email','htmlOptions'=>array( 'width'=>'15%' )),
array('name' => 'firstName', 'htmlOptions'=>array( 'width'=>'10%' ), 'value'=>'$data->firstname'),
array('name' => 'lastName', 'htmlOptions'=>array( 'width'=>'10%' ), 'value' => '$data->lastname'),
),
));
现在,当我查看这个网格时,排序工作在Id、电子邮件字段上,但不工作在firstName、lastName上
有谁能告诉我,在id和电子邮件字段上进行排序时,firsttName和lastName的排序有什么问题吗?您能发布属于
$criteria
的代码吗?最有可能的问题发生在那里。谢谢你的回复,我用搜索功能更新了我的问题。到目前为止看起来不错。您确定名字和姓氏中都有内容吗?没有指定,因此如果没有规则,这些字段将不会被填充。是的,我可以在网格中看到id、email、firstname和lastname的值。您已经用大写字母N
拼写了firstname
和lastname
。你试过小写吗?