Skip to content

Instantly share code, notes, and snippets.

@jamband
Created March 18, 2012 13:59
Show Gist options
  • Save jamband/2073201 to your computer and use it in GitHub Desktop.
Save jamband/2073201 to your computer and use it in GitHub Desktop.
Yii Framework: CDbCriteria sample.
<?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