Hi, I'm trying to implement a logic delete:
A field named active gets 0 when record is deleted, otherwise the default value is 1.
Question is, can I set a param in filters so when you look for a model it only takes the ones with active = 1?
Thanks
Page 1 of 1
Logic Delete
#2
Posted 18 January 2013 - 05:32 PM
In your model:
And in your "admin" view:
And finally in your '_search' view:
Now, you will have an 'Active' column with 'No/Yes' filter.
public function rules() { return array( //Other rules array('active', 'boolean', 'strict'=>TRUE, 'message'=>'Only boolean !'), ); } //other stuff public function search() { $criteria=new CDbCriteria; //Other criteria $criteria->compare('t.active', $this->active); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, 'pagination'=>array('pageSize'=>10), )); }
And in your "admin" view:
$this->widget('zii.widgets.grid.CGridView', array( 'id'=>'users-grid', 'dataProvider' => $model->search(), 'enablePagination' => true, 'filter' => $model, 'columns' => array( //Other columns array( 'name'=>'active', 'filter'=>array(0=>'No', 1=>'Yes'), 'type'=>'boolean', 'htmlOptions'=>array('style'=>'text-align:center'), ), 'class'=>'CButtonColumn', ), ));
And finally in your '_search' view:
<div class="row"> <?php echo $form->label($model,'active'); ?> <?php echo $form->checkBox($model,'active', array('checked'=>'checked', 'uncheckValue'=>0)); ?> </div>
Now, you will have an 'Active' column with 'No/Yes' filter.
#3
Posted 18 January 2013 - 05:36 PM
And in the 'components' section of your config/main.php file you may add:
Thank's that you will have all "No" in red color and all "Yes" in green color!
'format' => array( 'booleanFormat' => array('<span style="color:red">No</span>','<span style="color:green">Yes</span>'), ),
Thank's that you will have all "No" in red color and all "Yes" in green color!
Share this topic:
Page 1 of 1