Yii Framework Forum: How to use CActiveDataProvider with already defined scopes? - Yii Framework Forum

Jump to content

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

How to use CActiveDataProvider with already defined scopes? Rate Topic: -----

#1 User is offline   nobodysfault 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 14-December 09

Posted 17 January 2010 - 06:41 AM

I have created some model and some parameterized named scopes in it. And now i want to add some filtering options to data, displaying by CGridView, collected by CActiveDataProvider. I certainly can write something like this:
$dataProvider=new CActiveDataProvider('MyModel', array(
 'criteria'=>array(
  'condition'=>'param=:param',
   'params'=>array(
    ':param'=>$param,
...

but i don't want to duplicate already written conditions, defined in scopes. Now i use this:
$dataProvider->criteria->mergeWith(MyModel::model()->param($param)->getDbCriteria());

but maybe there is a better way to do this?
0

#2 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 18-April 09
  • Location:Leipzig, Germany

  Posted 18 January 2010 - 05:32 AM

You could try my extension CArrayDataProvider. It takes objects that can come from any array (scopes or child objects) and passes it over to CListView or CGridView.

Sorting and Pagination is not yet supported at this time, but it will be in the next version.
0

#3 User is offline   nobodysfault 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 14-December 09

Posted 18 January 2010 - 09:24 AM

Thanks, i'll try it
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