Simple extension that can be used to apply scopes to a CActiveDataProvider
protected/extensionsSee the following code example:
$dataProvider=new EActiveDataProvider('Post', array( 'scopes'=>array('published'), 'criteria'=>array( //'condition'=>'status=1 AND tags LIKE :tags', //'params'=>array(':tags'=>$_GET['tags']), 'with'=>array('author'), ), 'pagination'=>array( 'pageSize'=>20, ), )); $dataProvider->joinAll = true; // optional if you want to also join the *_MANY relations $dataProvider->getData(); // will return a list of Post objects
Total 3 comments
You can do it without extensions: $dataProvider=new CActiveDataProvider(Post::model()->published());
thanks!
I installed this a few days ago and it has simplified things tremendously for me.
I'm very curious why scopes weren't implemented by default -- is there a major performance hit when you're working with very large dataproviders?
Leave a comment
Please login to leave your comment.