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