Friday, February 22, 2013

YII: How to Customize the Admin action

If you want to add condition, you can do the following: 

1) copy-paste your action and change only name of it, for example "actionList"
2) change 2 lines of method search in your model to

public function search($param = array())
{
  $criteria=new CDbCriteria($param);
.....................................

3) copy-paste your admin view and rename it to "list" then open it and change line
'dataProvider'=>$model->search(),

to


'dataProvider'=>$model->search(array('condition'=>'column_name=1')),
 
// Added by me 
4) Or if you want to just use same "admin" view page, you can just add a variable:
 
                $this->render('admin',array(
   'model'=>$model, 'condition'=>$condition,
  ));
 
And in the admin view page, you can 
change it as below. 
'dataProvider'=>$model->search(array('condition'=>$condition)),
 
 
Reference:
http://www.yiiframework.com/forum/index.php/topic/13079-customising-the-admin-action-created-by-crud/
 

1 comment:

Admin said...

thank Brooo
Membantu sekali