Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Created May 30, 2012 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahisateru/2834901 to your computer and use it in GitHub Desktop.
Save tanakahisateru/2834901 to your computer and use it in GitHub Desktop.
Better AR with Yii - 3
<?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),
),
);
}
}
<?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