Customising the Admin action created by CRUD


The admin action of a controller which is generated by CRUD, by default shows all records of model when we click on manage link. I want to set a condition so that when clicked on manage, the admin action only shows record that satisfy some query criteria. where can i put criteria conditions for the admin query. the code of my admin action is given bellow, my controller name is MobileControler and model name is Mobile.

public function actionAdmin()


	$model=new Mobile('search');

	$model->unsetAttributes();  // clear any default values







In your model class Mobile

find method search

and after line

$criteria=new CDbCriteria


$criteria->condition='columnd_name =1';


columnd_name =1

your condition


What i need to do if i want to create a sperate action with this condition, so that existing admin action remains as it is. I Mean what i need to create new an action/ a model method / a view etc ?

  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);


  1. copy-paste your admin view and rename it to "list" then open it and change line




Great solution!

Just for the formality: add the new action to the accessRules and change the render in the new action to the new admin file

public function actionAdmin()


		$model=new Person('search');

		$model->unsetAttributes();  // clear any default values



		$this->render('admin',array(         //<----------here






Just a small remark: If you have table relations (also used in search criteria),

and if tables have same column name, then it needs to be specified, ex: