Yii Framework Forum: Adding A Pre-Condition To Data Loaded In Cgridview - Yii Framework Forum

Jump to content

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

Adding A Pre-Condition To Data Loaded In Cgridview Rate Topic: -----

#1 User is offline   Sukhwinder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 27-October 09

Posted 04 February 2013 - 01:10 AM

I have a post model, it is having attributes like section,category. in Gii generated code of admin controller, by default all the posts are loaded via Cactivedataprovider . But what i want is, to provide links/drop-down menu for the users to select a particular section or category, and then show the Posts having this particular section or category. so the value for the section/category will be taken from $_GET[]. How can i add this to tell Cactivedataprovider to load the posts of a particular category or section only?

Regards
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 579
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 04 February 2013 - 02:20 AM

Do as

1 - Create a dropdown with onChange reload the page with selected value(using javascript)
2 - In controller's action where you are calling for data i.e. CActiveRecord, use CDBCriteria to set the category for whom you want to list the articles

thanks
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   Sukhwinder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 27-October 09

Posted 04 February 2013 - 02:47 AM

View PostPeRoChAk, on 04 February 2013 - 02:20 AM, said:

Do as

1 - Create a dropdown with onChange reload the page with selected value(using javascript)
2 - In controller's action where you are calling for data i.e. CActiveRecord, use CDBCriteria to set the category for whom you want to list the articles

thanks


I am using Gii generated search() method, which in turn use CDbcriteria->compare() method for searching. since the paging and filtering is done using AJAX, so i am confuse how exactly to add a condition to existing $CDbcriteria->compare() statements?
0

#4 User is offline   softark 

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

Posted 04 February 2013 - 04:43 AM

Hi Sukhwinder,

Make use of the "advanced search form" in the gii generated admin page. The form should have the text field for category_id ... you can replace it with a dropdown list ... and the job is done. Your search() method should already have the code to handle searching by category_id.

Please read the following wiki for detailed explanation.
http://www.yiiframew...ivedataprovider
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