Skip to content

Instantly share code, notes, and snippets.

@jamband
Created November 8, 2012 07:18
Show Gist options
  • Save jamband/4037375 to your computer and use it in GitHub Desktop.
Save jamband/4037375 to your computer and use it in GitHub Desktop.
<?php
/**
* データを全件取得。ついでにページネーションとソートも
*/
public function getAll()
{
$c = new CDbCriteria();
return array(
$this->getPages($c),
$this->getSorts($c),
$this->findAll($c),
);
}
/**
* ページネーションをつくる
*/
public function getPages($c, $pageSize=10, $q=null)
{
$pages = new CPagination($this->count($c));
$pages->applyLimit($c);
$pages->params = $q ? compact('q') : null;
return $pages;
}
/**
* ソートをつくる
*/
public function getSorts($c)
{
$sort = new CSort();
$sort->modelClass = get_class();
$sort->defaultOrder = 't.id DESC';
$sort->applyOrder($c);
return $sort;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment