Yii Framework Forum: Cactivedataprovider And Search Method - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cactivedataprovider And Search Method Where pre-filter before render admin page? Rate Topic: -----

#1 User is offline   menxaca 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 121
  • Joined: 26-November 12
  • Location:Talavera de la Reina, Spain

Posted 15 April 2013 - 07:49 AM

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!
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 15 April 2013 - 07:57 AM

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

0

#3 User is offline   menxaca 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 121
  • Joined: 26-November 12
  • Location:Talavera de la Reina, Spain

Posted 15 April 2013 - 09:04 AM

It works! Thank you so much!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users