Created
May 30, 2012 09:11
-
-
Save tanakahisateru/2834868 to your computer and use it in GitHub Desktop.
Better AR with Yii - 2
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 newestFirst() | |
{ | |
$this->dbCriteria->order = 'created_on DESC'; | |
return $this; | |
} | |
} |
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() | |
), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment