Difference between #2 and #3 of
An easy way to use escopes and CActiveDataProvider

Changes

Title unchanged

An easy way to use escopes and CActiveDataProvider

Category unchanged

Tips

Yii version unchanged

Tags unchanged

CActiveDataProvider, scopes, gridview

Content changed

[...]
Eg:

```php
$ DataProvider = new CActiveDataProvider ('Post', array (
'
Ccriteria' => array ( 'Condition' => 'status = 1' 'Order' => 'DESC create_time' 'With' => array ('author') ) 'Ppagination' => array (
'PageSize' => 20,
)
[...]
```php
class MyActiveRecord extends CActiveRecord class extends {

/ **
[...]
* @ Return CActiveDataProvider
* /
public function getDataProvider
 ($ crit = eria=null, $ pagination = =null) {  if ((is_array ($ criteria)) | | $ CDbC($criteria instanceof CDbCriteria) )  $ T$this-> getDbCriteria () -> mergeWith ($ criteria);      $ P$pagination = CMap:: mergeArray (array ('pageSize' => 10), (array) $ pagination); return new CActiveDataProvider (__CLASS__, array ( 
 
(
 
   
'C         'criteria' => $ $this-> getDbCriteria (),          'P    'pagination' => $ pagination 'with' => array ('author') 
 
        )); 
 
    } 

 
        ));
 
    }
 

 
```
 
 
Edit the model...
 
 
```php 
class Post extends MyActiveRecord {
 
...
} 
```
[...]
```php
$ DataProvider = Post::
 model () -> with ('author') -> active () -> getDataProvider (); ... $ DataProvider = Post:: model () -> with ('author') -> active () -> getDataProvider (array ('order' => 'create_time DESC')); ... $ DataProvider = Post:: model () -> with ('author') -> active () -> getDataProvider (array ('order' => 'create_time DESC'), array ('pageSize' => 25)); ``` That's it!
1 1
10 followers
Viewed: 37 259 times
Version: 1.1
Category: Tips
Written by: Rafael Garcia
Last updated by: Rafael Garcia
Created on: Apr 14, 2011
Last updated: 13 years ago
Update Article

Revisions

View all history