Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How use pager function ?

cedced
edited September 2011 in Vanilla 2.0 - 2.8
Hi, i create a gallery application, but i don't understand how add the pager function inside ...

My model is
class GalleryModel {

public static function GetGallery($Offset = '0',$Limit = '', $Wheres = '') {
if ($Limit == '')
$Limit = Gdn::Config('Gallery.Media.PerPage', 8);

$Offset = !is_numeric($Offset) || $Offset < 0 ? 0 : $Offset;


$Result = Gdn::SQL()
->Select('m.*')
->From('Media m')
->OrderBy('m.MediaID','desc')
->Limit($Limit, $Offset)
->Get();
return $Result;
}


public static function GetCountGallery() {
$Result = Gdn::SQL()
->Select('m.*')
->From('Media m')
->Get();
return $Result;
}

}

my controller is :
public function index() {

$this->GalleryDataSet = GalleryModel::GetGallery();


$CountGallery = GalleryModel::GetCountGallery();
$this->SetData('CountGallery', $CountGallery);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure(
$Offset,
$Limit,
$CountGallery,
'gallery/%1$s'
);
$this->FireEvent('AfterBuildPager');

// Deliver JSON data if necessary
if ($this->DeliveryType() != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'gallery';
}

$this->Render();
}

and in my view i add :
<?php echo $this->Pager->ToString('more'); ?>

But no pager... someone have an idea ?
Tagged:

Comments

  • Options
    Enough content to get a pager?
  • Options
    yes, i have 30 results, and i display 8 with
    $Limit = Gdn::Config('Gallery.Media.PerPage', 8);

    (if i change to 100 perPage i have all my results)
  • Options
    SS ✭✭
    Yikes.
    OffsetLimit() function will help you...
Sign In or Register to comment.