コード例 #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 sfDoctrineFinderPager The initialized pager object
  */
 public function paginate($page = 1, $maxPerPage = 10)
 {
     // Children of sfDoctrinePager don't have a $class property, so we need to guess it
     $pager = new sfDoctrineFinderPager($this->class, $maxPerPage);
     $pager->setFinder($this);
     $pager->setPage($page);
     $pager->init();
     return $pager;
 }
コード例 #2
0
$t->is(@$articles[1]->getTitle(), 'tt2', 'sfDoctrineFinderPager::getResults() return an array of BaseObject instances');

$pager = new sfDoctrineFinderPager('DArticle', 2);
$pager->setPage(2);
$pager->init();

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

$pager = new sfDoctrineFinderPager('DArticle', 2);
$pager->setPage(3);
$pager->init();

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

$pager = new sfDoctrineFinderPager('DArticle', 2);
$finder = sfDoctrineFinder::from('DArticle')->
  where('Title', 'foo')->
  where('CategoryId', 1);
$pager->setFinder($finder);
$pager->init();