Skip to content

Instantly share code, notes, and snippets.

@jamband
Last active September 28, 2015 10:38
Show Gist options
  • Save jamband/1426071 to your computer and use it in GitHub Desktop.
Save jamband/1426071 to your computer and use it in GitHub Desktop.
<?php
class Hoge extends CActiveRecord
{
...
/**
* @see CActiveRecord::scopes()
*/
public function scopes()
{
return array(
'a' => array(
'condition' => 't.user_id = :user_id',
'params' => array(':user_id' => Yii::app()->user->id),
),
'b' => array(
'select' => 't.fuga, t.piyo',
'order' => 't.id DESC',
),
);
}
/**
* すべて取得
* @return array
*/
public function getAll()
{
$c = new CDbCriteria();
$count = $this->a()->count($c);
$pages = new CPagination($count);
$pages->pageSize = 30;
$pages->applyLimit($c);
return array(
$pages,
$this->a()->b()->findAll($c),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment