Advertisement
Guest User

Gallery Page with Pagination

a guest
Sep 10th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. class GalleryPage extends Page {
  4.  
  5. public static $has_many = array(
  6. 'GalleryImages' => 'GalleryImage'
  7. );
  8.  
  9. public static $defaults = array(
  10. 'ItemsperPage' => '10',
  11. 'ThumbnailImageWidth' => '100',
  12. 'ThumbnailImageHeight' => '100',
  13. 'FullImageWidth' => '800',
  14. 'FullImageHeight' => '600',
  15. );
  16.  
  17. public function getCMSFields() {
  18.  
  19. $fields = parent::getCMSFields();
  20.  
  21. $gridFieldConfig = GridFieldConfig_RecordEditor::create();
  22. $gridFieldConfig->addComponent(new GridFieldBulkEditingTools());
  23. $gridFieldConfig->addComponent(new GridFieldBulkImageUpload());
  24. $gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
  25.  
  26. $gridfield = new GridField("GalleryImages", "Gallery Images", $this->GalleryImages()->sort("SortOrder"), $gridFieldConfig);
  27.  
  28. $fields->addFieldToTab('Root.GalleryImages', $gridfield);
  29.  
  30. return $fields;
  31. }
  32. }
  33.  
  34. class GalleryPage_Controller extends Page_Controller {
  35.  
  36. public static $allowed_actions = array (
  37. );
  38.  
  39. public function Pagination() {
  40. // More info at http://doc.silverstripe.org/framework/en/howto/pagination
  41. $PaginatedList = new PaginatedList($this->data()->Images(), $this->request);
  42. $PaginatedList -> setPagelength(10);
  43. return $PaginatedList;
  44. }
  45.  
  46. public function getGalleryImages() {
  47. return $this->GalleryImages()->sort("SortOrder");
  48. }
  49. public function init() {
  50. parent::init();
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement