Yii Framework Forum: filter tin cgridview not work after alter search() method in issue model - Yii Framework Forum

Jump to content

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

filter tin cgridview not work after alter search() method in issue model

#1 User is offline   adipurwo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 05-March 12
  • Location:Indonesia

Posted 21 March 2012 - 12:01 AM

following chapter 6 page 144, i alter search() in Issue model.
public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('type_id',$this->type_id);
		$criteria->compare('status_id',$this->status_id);
		$criteria->compare('owner_id',$this->owner_id);
		$criteria->compare('requester_id',$this->requester_id);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user_id',$this->create_user_id);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user_id',$this->update_user_id);
// I ADD THIS CODE FOLLOWING THE BOOK
		$criteria->condition='project_id=:projectID';
		$criteria->params=array(':projectID'=>$this->project_id);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


but this modification cause the filter toolbar in cgridview in admin page not work. can you give me the solution? :D
0

#2 User is offline   adipurwo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 05-March 12
  • Location:Indonesia

Posted 21 March 2012 - 12:56 AM

View Postadipurwo, on 21 March 2012 - 12:01 AM, said:

following chapter 6 page 144, i alter search() in Issue model.
public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('type_id',$this->type_id);
		$criteria->compare('status_id',$this->status_id);
		$criteria->compare('owner_id',$this->owner_id);
		$criteria->compare('requester_id',$this->requester_id);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('create_user_id',$this->create_user_id);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user_id',$this->update_user_id);
// I ADD THIS CODE FOLLOWING THE BOOK
		$criteria->condition='project_id=:projectID';
		$criteria->params=array(':projectID'=>$this->project_id);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


but this modification cause the filter toolbar in cgridview in admin page not work. can you give me the solution? :D


i found the solution. the solution is don't alter search() method in issue model. our modification in actionAdmin() method in issueController class just enough to achieve the goal (to restrict admin search for only current project context) :D
0

#3 User is offline   Alex Gz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 12-April 12

Posted 12 April 2012 - 05:19 PM

Thanks for posting your solution, it helped me a lot!
0

#4 User is offline   Th3 R00ST3R 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-February 12

Posted 16 April 2012 - 12:13 PM

Can you post an example of your solution in the Controller?

Thanks!
0

#5 User is offline   adipurwo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 05-March 12
  • Location:Indonesia

Posted 23 July 2012 - 08:15 AM

View PostTh3 R00ST3R, on 16 April 2012 - 12:13 PM, said:

Can you post an example of your solution in the Controller?

Thanks!

the book has explain this step-by-step. the wrong one is only instruction for altering search() method in issue model. but as you wanted i'd like to explain it.
this actionAdmin() method part:
	/**
	 * @var private property containing the associated Project model instance
	 */
// This addition private variable for retain associated project_id of the issue 
	private $_project=null;

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new Issue('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['Issue']))
			$model->attributes=$_GET['Issue'];

// Assign value for the project_id attribute of $model object by filling it with associated project_id of the issue  
// This would restrict admin search for only current project context
		$model->project_id = $this->_project->id;

		$this->render('admin',array(
			'model'=>$model,
		));
	}

1

#6 User is offline   cenarius 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 29-March 13

Posted 05 July 2013 - 04:01 AM

View Postadipurwo, on 21 March 2012 - 12:56 AM, said:

i found the solution. the solution is don't alter search() method in issue model. our modification in actionAdmin() method in issueController class just enough to achieve the goal (to restrict admin search for only current project context) :D


i have same issue, and here is my solution
public function search() {
        $criteria=new CDbCriteria;
        $criteria->compare('no_mesin',$this->no_mesin,true);
        $criteria->addSearchCondition('status','A');
        //$criteria->condition="status='A'";
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

1

#7 User is offline   savariya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 19-February 13
  • Location:india

Posted 24 October 2013 - 10:55 AM

Thanks cenarius.

your solution is Rocks...


thanks a lot.
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