Created
November 8, 2012 07:18
-
-
Save jamband/4037375 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* データを全件取得。ついでにページネーションとソートも | |
*/ | |
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