Created
May 30, 2012 09:14
-
-
Save tanakahisateru/2834901 to your computer and use it in GitHub Desktop.
Better AR with Yii - 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo extends CActiveRecord { | |
public function scopes() | |
{ | |
return array( | |
'newestFirst'=>array( | |
'order'=>'created_on DESC', | |
), | |
'newestLast'=>array( | |
'order'=>'created_on ASC', | |
), | |
'onlyUnread'=>array( | |
'condition'=>array('read', 0), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FooController extends Controller { | |
public function actionIndex() | |
{ | |
$this->render('index',array( | |
'dataProvider' => new CActiveDataProvider( | |
Foo::model()->newestFirst() | |
), | |
)); | |
} | |
public function actionUnreads() | |
{ | |
$this->render('unreads',array( | |
'dataProvider' => new CActiveDataProvider( | |
Foo::model()->onlyUnread()->newestLast() | |
), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment