Yii CActiveDataProvider with scopes
If you ever wondered how to restrict the data provider to a given scope here's the easiest way:
public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('Orders');
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}becomes:
public function actionIndex()
{
    $model = Orders::model()->own()->published();
    $dataProvider=new CActiveDataProvider($model);
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}The CActiveDataProvider class accepts ActiveRecord object as first parameter in the constructor.
Written by Ilko
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Yii 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
