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've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Comments in DataObject Page

Go to End

5 Posts   2327 Views


Community Member, 17 Posts

27 January 2012 at 8:33pm

Hi all,

is there way to have comments in DataObject page?
I can view module in the page, i can insert comment, send email to admin when comment is
published, but the comment is published in all DataObject Pages.

Sorry for my english..

my Holder page is this:



class CategoryPage extends Page

public static $has_one = array(
'CategoryBanner' => 'Image'

public static $many_many = array(
'Products' => 'Product'

public static $has_many = array (
'Immagini' => 'Immagine',
'ImmaginiGalleria' => 'ImmagineGalleria'

static $allowed_children = array(
'none' => 'none'

public function getCMSFields()
$fields = parent::getCMSFields();

$fields = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'ImmaginiGalleria', // Source name
'ImmagineGalleria', // Source class
'Descrizione' => 'Descrizione',
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
$fields->addFieldToTab("Root.Content.ImmaginiGalleria", $manager);

return $fields;

class CategoryPage_Controller extends Page_Controller

static $allowed_actions = array(

public function init()


//Return the list of products for this category
public function getProductsList()
return $this->Products(Null, 'Epoca ASC');

//Get's the current product from the URL, if any
public function getCurrentProduct()
$Params = $this->getURLParams();
$URLSegment = Convert::raw2sql($Params['ID']);

if($URLSegment && $Product = DataObject::get_one('Product', "URLSegment = '" . $URLSegment . "'"))
return $Product;

//Shows the Product detail page
function show()
//Get the Product
if($Product = $this->getCurrentProduct())
$Data = array(
'Product' => $Product,
'MetaTitle' => $Product->MetaTitle

//return our $Data array to use, rendering with the template
return $this->customise($Data)->renderWith(array('ProductPage', 'Page'));
else //Product not found
return $this->httpError(404, 'Sorry that product could not be found');

//Generate out custom breadcrumbs
public function Breadcrumbs() {

//Get the default breadcrumbs
$Breadcrumbs = parent::Breadcrumbs();

if($Product = $this->getCurrentProduct())
//Explode them into their individual parts
$Parts = explode(SiteTree::$breadcrumbs_delimiter, $Breadcrumbs);

//Count the parts
$NumOfParts = count($Parts);

//Change the last item to a link instead of just text
$Parts[$NumOfParts-1] = ('<a href="' . $this->Link() . '">' . $Parts[$NumOfParts-1] . '</a>');

//Add our extra piece on the end
$Parts[$NumOfParts] = $Product->Title;

//Return the imploded array
$Breadcrumbs = implode(SiteTree::$breadcrumbs_delimiter, $Parts);

return $Breadcrumbs;

function InfoForm() {
// Create fields
$Params = Director::urlParams();

$fields = new FieldSet(
new TextField('Nome', 'Nome *'),
new TextField('Cognome', 'Cognome *'),
new EmailField('Email', 'Email *'),
new TextareaField('Note','Note'),
new HiddenField ('Info','Info',$this->Titolo),
new PhpCaptchaField('Captcha','')

// Create action
$actions = new FieldSet(
new FormAction('SendInfoForm', 'Invia')
// Create action

$validator = new RequiredFields('Nome', 'Cognome', 'Email');

return new Form($this, 'InfoForm', $fields, $actions, $validator);

function SendInfoForm($data) {

//Set data
$From = $data['Email'];
$To = "";
$Subject = "Modulo Informazioni dal sito Giuseppediprinzio";
$email = new Email($From, $To, $Subject);
//set template
//populate template
//send mail
//return to submitted message

Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");
public function Success()
return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";



My Product Page is this




class Product extends DataObject
static $db = array(
'Title' => 'Varchar(255)',
'Description' => 'HTMLText',
'URLSegment' => 'Varchar(255)',
'MetaTitle' => 'Varchar(255)',
"Epoca" => "Enum(' , Anni ’20 - ’40, Anni ’40 - ’50, Anni ’50 - ’60, Anni ’60 - ’80, Anni ’80 - ’90, Anni ’90 - ’99', '')",
"Materiale" => "Enum(' , Terracotta, Ceramica Policroma, Carta, Gesso, Bronzo, Cera, Pietra, Argento', '')",
"Tipologia" => "Enum(' , Bassorilievo, Altorilievo, Tuttotondo, Incisione, Schizzo, Disegno b/n, Disegno colorato, Piatto Smaltato, Piastrella Dipinta', '')",
"Cani" => "Boolean",
"Cavalli" => "Boolean",
"CavalliAlati" => "Boolean",
"Centauri" => "Boolean",
"Donne" => "Boolean",
"Uomini" => "Boolean",
"Angeli" => "Boolean",
"Santi" => "Boolean",
"Bambini" => "Boolean",
"Paesaggi" => "Boolean",
"Barche" => "Boolean",
"Case" => "Boolean",
"Paesi" => "Boolean",
"Astratto" => "Boolean",
"Colombe" => "Boolean",
"Nudo" => "Boolean"

//Set our defaults
static $defaults = array(
'Title' => 'New Product',
'URLSegment' => 'new-product'

static $has_one = array(
'Image' => 'Image'

//Relate to the category pages
static $belongs_many_many = array(
'Categories' => 'CategoryPage'

//Fields to show in ModelAdmin table
static $summary_fields = array(
'Thumb' => 'Foto',
'Title' => 'Title',
'URLSegment' => 'URLSegment',

//Add an SQL index for the URLSegment
static $indexes = array(
"URLSegment" => true

//Fields to search in ModelAdmin
static $searchable_fields = array (
'Categories.ID' => array(
'title' => 'Category'

//Generate our thumbnail for the DOM
public function getThumb()
if($this->ImageID && $this->Image())
return $this->Image()->CMSThumbnail();
return '(No Image)';

function getCMSFields()
$fields = parent::getCMSFields();

//Main Tab
$fields->addFieldToTab("Root.Main", new TextField('Title', 'Title'));
$fields->addFieldToTab("Root.Main", new TextField('URLSegment', 'URL Segment'));
$fields->addFieldToTab("Root.Main", new TextField('MetaTitle', 'Meta Title')); $fields->addFieldsToTab('Root.SchedaOpera', array(new DropdownField('Epoca', 'Epoca', $this->dbObject('Epoca')->enumValues())));
$fields->addFieldsToTab('Root.SchedaOpera', array(new DropdownField('Materiale', 'Materiale', $this->dbObject('Materiale')->enumValues())));
$fields->addFieldsToTab('Root.SchedaOpera', array(new DropdownField('Tipologia', 'Tipologia', $this->dbObject('Tipologia')->enumValues())));
$fields->addFieldToTab('Root.SchedaOpera', new LabelField ("Soggetti","Soggetti:"));

$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Cavalli","Cavalli"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("CavalliAlati","Cavalli Alati"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Cani","Cani"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Centauri","Centauri"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Donne","Donne"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Uomini","Uomini"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Angeli","Angeli"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Santi","Santi"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Bambini","Bambini"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Paesaggi","Paesaggi"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Barche","Barche"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Case","Case"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Paesi","Paesi"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Astratto","Astratto"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Colombe","Colombe"));
$fields->addFieldsToTab('Root.SchedaOpera', new CheckBoxField("Nudo","Nudo"));
$fields->addFieldToTab("Root.Main", new HTMLEditorField('Description','Descrizione'));
$Categories = DataObject::get('CategoryPage');
$fields->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categorie', $Categories));

$fields->addFieldToTab("Root.Immagini", new ImageField('Image', 'Immagine', Null, Null, Null, 'Opere/'));

return $fields;

//Set URLSegment to be unique on write
function onBeforeWrite()
// If there is no URLSegment set, generate one from Title
if((!$this->URLSegment || $this->URLSegment == 'new-product') && $this->Title != 'New Product')
$this->URLSegment = SiteTree::generateURLSegment($this->Title);
else if($this->isChanged('URLSegment'))
// Make sure the URLSegment is valid for use in a URL
$segment = preg_replace('/[^A-Za-z0-9]+/','-',$this->URLSegment);
$segment = preg_replace('/-+/','-',$segment);

// If after sanitising there is no URLSegment, give it a reasonable default
if(!$segment) {
$segment = "product-$this->ID";
$this->URLSegment = $segment;

// Ensure that this object has a non-conflicting URLSegment value.
$count = 2;
$this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;


//Test whether the URLSegment exists already on another Product
function LookForExistingURLSegment($URLSegment)
return (DataObject::get_one('Product', "URLSegment = '" . $URLSegment ."' AND ID != " . $this->ID));

//Generate the link for this product
function Link()
//if we are on a category page return that
if(Director::CurrentPage()->ClassName == 'CategoryPage')
$Category = Director::CurrentPage();
//Otherwise just grab the first category this product is in
$Category = $this->Categories()->First();
//Check we have a category then return the link
return $Category->absoluteLink() . 'show/' . $this->URLSegment;
function AbsoluteLink() {
return Director::absoluteURL($this->Link());


If I add $PageComments in my .ss template when submit it, comment appear in each product...

I hope anyone help me.




Community Member, 17 Posts

31 January 2012 at 4:46am

Anyone can help me?


Carbon Crayon

Community Member, 598 Posts

1 February 2012 at 11:12am

hi Jmax,

Unfortunately there is no simple way to add Comments to data-objects. For we wrote our own Comment system to allow commenting.

At it's core its simply a case of having a form which submits to the HolderPage controller and contains the DO's ID in a hidden field, which you can then Attach it using a has_many relationship.



Community Member, 17 Posts

1 February 2012 at 11:27am

Thanks Aram,

it's not simple for me.. :-(

i'll try...


Forum Moderator, 5523 Posts

8 February 2012 at 9:34pm

jmax - try the comments module. Comments has been stripped out for 3.0 and includes the ability to work on DataObject. While it's still a very early stage and designed for 3.0 rather than 2.4, it may provide a good start for you.