Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Adding a simple picture gallery (SPGM)

Go to End

9 Posts   5759 Views


Community Member, 46 Posts

27 January 2009 at 12:37am

Edited: 27/01/2009 5:22pm


I've been trying to add SPGM (Simple Picture Gallery Manager) to a page in the CMS.

To achieve this, I used the method described in Recipes: Customising content in your templates

So I added the following in the Page.php file in the Page_Controller class:

	function Content() {
  return str_replace('$Gallery', $this->GalleryDisplay(), $this->Content);

//  $this->GalleryDisplay() string up 2 lines?calls the GalleryDisplay() method below
function GalleryDisplay() {
  require ('../../spgm/spgm.php');

Then put $Gallery in my content field where I want the gallery.

But when I try to call the page I get an error message: Fatal error: Page_Controller::require() [function.require]: Failed opening required '../../spgm/spgm.php' ... I believe that the path is correct, I'm not sure where to look now. If I let the method GalleryDisplay() output text, it works fine by the way.

Does anybody have advice on how to successfully include a php script? Or with adding the gallery? Is there a better way of doing it?


Carbon Crayon

Community Member, 598 Posts

27 January 2009 at 12:57am

Hi Kaydee

Im not entirely sure what you are trying to do, but be aware that each page is run from the root, so you dont need the ../../ on the front of your URL. That might fix it.

Also have you looked into the gallery, Image gallery and HasManyFilemanager extentions? Together they provide most of the gallery solutions you might want. If your looking for a really simple way to just add a number of images to a page then the latter is really good.

hope that helps



Community Member, 46 Posts

27 January 2009 at 1:27am

Thanks for the speedy reply, aram!

leaving out the ../../ doesn't fix the problem, unfortunately.

Funnily enough I discovered the gallery extension just after posting my message. (previously hadn't seen it as was under "unsupported modules") . The thing is, of the SPGM I know that it works, because as standalone it does. But I'll try the extensions suggested by you and post my experiences.

Thanks again


Community Member, 46 Posts

29 January 2009 at 2:48pm

Edited: 29/01/2009 2:48pm


I have tried the Gallery module in the meantime, works fine and it looks great!

Still, I would like to also be able to create a really simple gallery, and I liked the idea mentioned in this forum post . However, I don't manage to get it going. The tables were created correctly, no problem. I also managed to create a SimpleGalleryHolder page and SimpleGallery page. (I called it SimpleGallery so not to interfere with already set up Gallery)

However, when I try to view the gallery page, I get the following error message:

FATAL ERROR: Object::__call() Method 'setURLParams' not found in class 'SimpleGalleryPage'
At line 199 in (..)\silverstripe\sapphire\core\Object.php

Can anyone explain where this error comes from? I couldn't find anything about the Method stURLParams in the documentation. Your help is much appreciated.



Forum Moderator, 5523 Posts

29 January 2009 at 3:40pm

Kaydee, it might help if you post your code :)


Community Member, 46 Posts

29 January 2009 at 4:08pm

Edited: 29/01/2009 4:08pm

Hi Willr,

The code is almost the same as in the post mentioned above, just with different names.



class SimpleGalleryHolder extends Page {
// gallery pages are the default page to be created under a holder
static $default_child = "SimpleGalleryPage";

// only gallery pages are allowed under a holder section
   static $allowed_children = array("SimpleGalleryPage");
    * Return the gallery pages with a limit you can set in template
* default is 5 if nothing set
   function SimpleGalleryItems($limit = 5) {
      return DataObject::get("SimpleGalleryPage","`ParentID` = '{$this->ID}'", "", "", $limit);




class SimpleGalleryPage extends Page {

// define your database fields here - for example we have author
   static $db = array(
      "Author" => "Varchar(100)"

// define image class relationships here (see SimpleGalleryPage_Image class below)
// Kaydee: I changes this, as I believe there was an error with naming in code posted by Sean
   static $has_one = array(
      "SimpleGalleryPage_Image" => "Image"
   function getCMSFields($cms) {
      $fields = parent::getCMSFields($cms);
      $fields->addFieldToTab("Root.Content.Main", new TextField("Author","Picture author"));
$fields->addFieldToTab("Root.Content.Main", new ImageField("SimpleGalleryPage_Image", "Picture"));
      return $fields;
class SimpleGalleryPage_Image extends Image {
// define different GD functions to resize uploaded photos, see the GD page in the SilverStripe documentation for different functions for resampling

   function generateThumbnail($gd) {
      return $gd->resizeByWidth(288);
   function generateNormal($gd) {
      return $gd->resizeByWidth(395);


And here the templates:

<div id="SimpleGallery">
   <% if SimpleGalleryItems %>
      <ul class="galleryList">
<!-- define limit in brackets -->
      <% control SimpleGalleryItems(10) %>
            <img src="$Image.Thumbnail.URL" alt="$Title photo" >
            <p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>
      <% end_control %>
   <% end_if %>

   <img src="$Image.Normal.URL" alt="$Title photo" >
   <p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>    

In this code there are some slight changes from the code originally written by Sean in the post mentioned above. But I had also tried it with his code, before setting up the gallery module, and I got the same error message.

Thanks for your help


Forum Moderator, 5523 Posts

29 January 2009 at 4:17pm

Your pages are missing controllers?

In all your class MyClass extends Page {} you also need a matching class MyClass_Controller extends Page_Controller {} underneath it


Community Member, 46 Posts

29 January 2009 at 4:35pm

Thanks a lot!

This really shows I'm a newbie ;) I actually know this thing about the Controller (have done the first two tutorials) , but I just blindly copied the code. Will try now with controllers in place!


Go to Top