Created
March 18, 2012 13:59
-
-
Save jamband/2073201 to your computer and use it in GitHub Desktop.
Yii Framework: CDbCriteria sample.
This file contains hidden or 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 Hoge extends CActiveRecord | |
{ | |
... | |
/** | |
* 最新のデータを$limit分取得する | |
*/ | |
public function getRecent($limit=5) | |
{ | |
$c = new CDbCriteria; | |
$c->select = 't.fuga, t.piyo'; | |
$c->condition = 't.userid = :userid'; | |
$c->addCondition('t.is_deleted = 0'); | |
$c->params[':userid'] = Yii::app()->user->id; | |
$c->order = 't.create_time DESC'; | |
$c->limit = $limit; | |
return $this->findAll($c); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment