5099 Posts in 1519 Topics by 1116 members
| Go to End | Next > | |
| Author | Topic: | 3814 Views |
-
Adding a simple picture gallery (SPGM)

27 January 2009 at 12:37am Last edited: 27 January 2009 5:22pm
Hello,
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?
Cheers,
K -
Re: Adding a simple picture gallery (SPGM)

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
aram
-
Re: Adding a simple picture gallery (SPGM)

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
kaydee -
Re: Adding a simple picture gallery (SPGM)

29 January 2009 at 2:48pm Last edited: 29 January 2009 2:48pm
Hi,
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.
K
-
Re: Adding a simple picture gallery (SPGM)

29 January 2009 at 3:40pm
Kaydee, it might help if you post your code
-
Re: Adding a simple picture gallery (SPGM)

29 January 2009 at 4:08pm Last edited: 29 January 2009 4:08pm
Hi Willr,
The code is almost the same as in the post mentioned above, just with different names.
SimpleGalleryHolder.php:
<?php
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);
}
}?>
SimpleGalleryPage.php:
<?php
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) {
$gd->setQuality(90);
return $gd->resizeByWidth(288);
}
function generateNormal($gd) {
$gd->setQuality(90);
return $gd->resizeByWidth(395);
}
}?>
And here the templates:
SimpleGalleryHolder.ss
<div id="SimpleGallery">
<% if SimpleGalleryItems %>
<ul class="galleryList">
<!-- define limit in brackets -->
<% control SimpleGalleryItems(10) %>
<li>
<h3>$Title</h3>
<img src="$Image.Thumbnail.URL" alt="$Title photo" >
<p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>
</li>
<% end_control %>
</ul>
<% end_if %>
</div>SimpleGalleryPage.ss
<h2>$Title</h2>
<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
K -
Re: Adding a simple picture gallery (SPGM)

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
-
Re: Adding a simple picture gallery (SPGM)

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!
Cheers,
K
| 3814 Views | ||
| Go to Top | Next > |



