Cactivedataprovider And Search Method

Hi All,

I’m trying to user admin action with search method for displaying a grid, but… I need to filter the model in somewhere before render the page by foreign key, something like:




    public function actionAdmin()

	{

		$model=new Ads('search');


		if (isset($_GET['id']))

                    $model->setAttributes(array('cause_id'=> $_GET['id']));


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


		if(isset($_GET['Ads']))

			$model->attributes=$_GET['Ads'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}



It doesn’t work, also I tried to prefilter in search method, but doesn’t work either. I have read this wiki, that is really helpful for some things, but I don’t get myself in the right direction, how to do it?

Thanks!

Hi menxaca,

Maybe this?




    public function actionAdmin()

	{

		$model=new Ads('search');

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

		if (isset($_GET['id']))

                    $model->cause_id = $_GET['id'];


		if(isset($_GET['Ads']))

			$model->attributes=$_GET['Ads'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}



It works! Thank you so much!