Yii1 删除初始搜索
Yii1 Remove initial Search
我在尝试显示 CGridView
上的元素列表时遇到问题,我有一个带有布尔字段 is_active
的 table,我们 0
默认值,所以当我想在 CGridView
上显示此 table 时,它只显示 is_active 字段上带有 0 的行,默认情况下在搜索输入上添加 0
。
我将此行添加到搜索功能 $criteria->compare('is_active',$this->is_active,false);
但仍然无法正常工作
这是我的搜索功能
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title);
$criteria->compare('description',$this->description);
$criteria->compare('is_active',$this->is_active,false);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
这是我的 CGridView
...
{
'header' : 'Activated',
'filter' : CHtml.activeTextField( model, 'is_active' ),
'value' : '$data->is_active ? "Oui" : "Non" '
}
...
这是我得到的
但我想要的是显示所有 table 的元素。
您需要使用 unsetAttributes()
重置从数据库架构检测到的默认值:
$model = new MyModel('search');
$model->unsetAttributes();
if (isset($_GET['MyModel'])) {
$model->attributes = $_GET['MyModel'];
}
$dataProvider = $model->search();
我在尝试显示 CGridView
上的元素列表时遇到问题,我有一个带有布尔字段 is_active
的 table,我们 0
默认值,所以当我想在 CGridView
上显示此 table 时,它只显示 is_active 字段上带有 0 的行,默认情况下在搜索输入上添加 0
。
我将此行添加到搜索功能 $criteria->compare('is_active',$this->is_active,false);
但仍然无法正常工作
这是我的搜索功能
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title);
$criteria->compare('description',$this->description);
$criteria->compare('is_active',$this->is_active,false);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
这是我的 CGridView
...
{
'header' : 'Activated',
'filter' : CHtml.activeTextField( model, 'is_active' ),
'value' : '$data->is_active ? "Oui" : "Non" '
}
...
这是我得到的
但我想要的是显示所有 table 的元素。
您需要使用 unsetAttributes()
重置从数据库架构检测到的默认值:
$model = new MyModel('search');
$model->unsetAttributes();
if (isset($_GET['MyModel'])) {
$model->attributes = $_GET['MyModel'];
}
$dataProvider = $model->search();