Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Created May 30, 2012 09:11
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/2834868 to your computer and use it in GitHub Desktop.
Save tanakahisateru/2834868 to your computer and use it in GitHub Desktop.
Better AR with Yii - 2
<?php
class Foo extends CActiveRecord {
public function newestFirst()
{
$this->dbCriteria->order = 'created_on DESC';
return $this;
}
}
<?php
class FooController extends Controller {
public function actionIndex()
{
$this->render('index',array(
'dataProvider' => new CActiveDataProvider(
Foo::model()->newestFirst()
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment