Yii 1.1: active-data-provider-with-scopes

Use scopes in CActiveDataProvider
3 followers

Simple extension that can be used to apply scopes to a CActiveDataProvider

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Usage

See 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

Change Log

September 7, 2010

  • Update to make it work with Yii 1.1.4

March 19, 2010

  • Initial release.

Total 3 comments

#4699 report it
Nayjest at 2011/08/05 04:35am
Applying scopes without extended data provider

You can do it without extensions: $dataProvider=new CActiveDataProvider(Post::model()->published());

#123 report it
thorfinn at 2010/09/05 07:19am
very useful!

thanks!

#655 report it
Dana at 2010/03/27 02:12pm
Easy to use and very effective

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 to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: Troto
  • Category: Database
  • Votes: +5
  • Downloaded: 1,230 times
  • Created on: Mar 19, 2010
  • Last updated: Oct 4, 2010