Hi all, i am trying to make a basic gallery & add the CMSThumbnail but its not working for me.. here is the coe below :
SGalleryImage.php
<?php
class SGalleryImage extends DataObject {
/*
public static $plural_name = 'Gallery Images';
public static $singular_name = 'Gallery Image';
*/
static $db = array(
'Name' => 'Varchar(255)',
'Caption' => 'Text',
'SortID' => 'Int'
);
static $has_one = array(
'Image' => 'Image',
'SGallery' => 'SGallery'
);
// Summary fields
public static $summary_fields = array(
'Name' => 'Name',
'Caption' => 'Caption',
//"Image => 'Image',
);
function SummaryOfImage() {
if ($Image = $this->Image())
return $Image->CMSThumbnail();
else
return '(No Image)';
}
}
SGallery.PHP
<?php
Class SGallery extends Page {
static $singular_name = 'SGallery';
static $plural_name = 'SGalleries';
static $icon = '';
static $db = array(
'GalleryDesc' => "Text"
);
static $has_one = array(
'Folder' => 'Folder',
'CoverImage' => 'Image'
);
public static $has_many = array(
'Images' => 'SGalleryimage'
);
//*
function getCMSFields() {
$fields = parent::getCMSFields();
/*
* Add extra basic fields to the CMS + Extra Tab
* $newFieldsArray = list of fields need to be added to tab
* $newFieldsArray MUST be used to add array of fields as fields need to be declared before they can be added to a tab !
*/
$newFieldsArray = array(
new UploadField("CoverImage"),
new TextareaField("GalleryDesc")
);
$fields->addFieldsToTab("Root.Settings", $newFieldsArray, "");
/*
* Add Gallery Section to the page using has_many relation + GridFeild
*/
$config = GridFieldConfig_RelationEditor::create();
$config->addComponents(
new GridFieldSortableRows($this->Images->SortID)
);
/*
*
$config->setDisplayFields(array(
'ID' => 'ID',
'Title' => 'Title'
));
*
*/
$field = new GridField("SGalleryimages", "SGallery images", $this->Images(), $config);
$fields->addFieldToTab("Root.GalleryImages", $field);
return $fields;
}
/*
* Attempt to create custom folder for each SGallerypage
function findOrMakeFolder() {
$Title = SiteTree::generateURLSegment($this->Title);
if ($this->Folder() && $this->Folder()->exists()) {
$folder = $this->Folder();
} else {
$folder = Folder::findOrMake($Title);
$folder->write();
}
$folder->Name =$Title;
$folder->Title = $Title;
$this->FolderID = $folder->ID;
$folder->write();
}
*
*/
function onBeforeWrite() {
parent::onBeforeWrite();
//$this->findOrMakeFolder();
}
function onBeforeDelete() {
parent::onBeforeDelete();
}
function ClassName() {
return __CLASS__;
}
}
class SGallery_Controller extends Page_Controller {
function init() {
parent::init();
}
function RenderGallery($TemplateName=NULL) {
$renderdImages = $this->data()->Images . renderWith;
return $renderdImages;
}
}