コード例 #1
0
 /**
  * Prepares a pager based on the finder
  * The pager is initialized (it knows how many pages it contains)
  * But it won't be populated until you call getResults() on it
  *
  * @param integer $page The current page (1 by default)
  * @param integer $maxPerPage The maximum number of results per page (10 by default)
  *
  * @return sfPropelFinderPager The initialized pager object
  */
 public function paginate($page = 1, $maxPerPage = 10)
 {
     // Children of sfPropelPager don't have a $class property, so we need to guess it
     $pager = new sfPropelFinderPager($this->class, $maxPerPage);
     $pager->setFinder($this);
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
コード例 #2
0
$t->is(@$articles[1]->getTitle(), 'tt2', 'sfPropelFinderPager::getResults() return an array of BaseObject instances');

$pager = new sfPropelFinderPager('Article', 2);
$pager->setPage(2);
$pager->init();

$t->is($pager->getNbResults(), 5, 'sfPropelFinderPager::getNbResults() return the total nb of results');
$t->is($pager->getLastPage(), 3, 'sfPropelFinderPager::getLastPage() return the total nb of pages');
$t->is($pager->getFirstIndice(), 3, 'sfPropelFinderPager::getFirstIndice() return offset of the first result of the page');
$articles = $pager->getResults();
$t->is(count($articles), 2, 'sfPropelFinderPager::getResults() return an array of max $maxPerPage results');
$t->is(@$articles[0]->getTitle(), 'tt3', 'sfPropelFinderPager::getResults() return an array of BaseObject instances');
$t->is(@$articles[1]->getTitle(), 'tt4', 'sfPropelFinderPager::getResults() return an array of BaseObject instances');

$pager = new sfPropelFinderPager('Article', 2);
$pager->setPage(3);
$pager->init();

$t->is($pager->getNbResults(), 5, 'sfPropelFinderPager::getNbResults() return the total nb of results');
$t->is($pager->getLastPage(), 3, 'sfPropelFinderPager::getLastPage() return the total nb of pages');
$t->is($pager->getFirstIndice(), 5, 'sfPropelFinderPager::getFirstIndice() return offset of the first result of the page');
$articles = $pager->getResults();
$t->is(count($articles), 1, 'sfPropelFinderPager::getResults() return an array of max $maxPerPage results');
$t->is(@$articles[0]->getTitle(), 't5', 'sfPropelFinderPager::getResults() return an array of BaseObject instances');

$pager = new sfPropelFinderPager('Article', 2);
$finder = sfPropelFinder::from('Article')->
  where('Title', 'foo')->
  where('CategoryId', 1);
$pager->setFinder($finder);
$pager->init();