I'm having problems trying to display a list of elements on CGridView
,I have a table with a boolean field is_active
who had us 0
default value, so when I want to display this table on CGridView
it show just the rows with 0 on is_active field and add 0
on search input by default.
I add this line to search function $criteria->compare('is_active',$this->is_active,false);
but stil not working
This is my search function
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,
));
}
This is my CGridView
...
{
'header' : 'Activated',
'filter' : CHtml.activeTextField( model, 'is_active' ),
'value' : '$data->is_active ? "Oui" : "Non" '
}
...
This what I got
But wat I want is to show all table's elements.
You need to use unsetAttributes()
to reset default values detected from database schema:
$model = new MyModel('search');
$model->unsetAttributes();
if (isset($_GET['MyModel'])) {
$model->attributes = $_GET['MyModel'];
}
$dataProvider = $model->search();