【问题标题】:Yii1 Remove initial SearchYii1 删除初始搜索
【发布时间】:2019-03-11 08:51:30
【问题描述】:

我在尝试在 CGridView 上显示元素列表时遇到问题,我有一个带有布尔字段 is_active 的表,我们有 0 默认值,所以当我想在 @ 上显示此表时987654326@ 它只显示 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" '
}
...

这是我得到的

但我想要的是显示所有表格的元素。

【问题讨论】:

    标签: gridview yii grid yii1.x


    【解决方案1】:

    您需要使用unsetAttributes() 重置从数据库架构中检测到的默认值:

    $model = new MyModel('search');
    $model->unsetAttributes();
    if (isset($_GET['MyModel'])) {
        $model->attributes = $_GET['MyModel'];
    }
    $dataProvider = $model->search();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2019-01-21
      • 1970-01-01
      相关资源
      最近更新 更多