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 forum.silverstripe.org 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.

Data Model Questions /

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

Best Practices Extending SiteTree


Go to End


4 Posts   1389 Views

Avatar
zenmonkey

Community Member, 545 Posts

31 July 2013 at 7:18am

Just wondering if there any Best Practices in SS3.1 when adding DataExtensions to the base Page. Is it better to add the DataExtension to SiteTree or to Page?

Avatar
copernican

Community Member, 189 Posts

31 July 2013 at 7:33am

I always add my DataExtension to Page. In the almost 3 years I've been developing with SS I've never created a new page type that extended SiteTree.

not sure if there is a best practice but this what I've always done.

Avatar
zenmonkey

Community Member, 545 Posts

31 July 2013 at 12:13pm

I'm thinking more in terms of adding features to the basic Page as opposed to creating new Page types. I was thinking doing it to SiteTree to save creating another an extra Table. If you add the DataExtentsion to Page it creates a Page Table for the new fields, but if you add it to SiteTree it just adds the extra fields to the SiteTree table. I figure that way it saves a DataBase call, and a table. But I was wondering if there's a conflict with any intended design patterns

Avatar
Optic Blaze

Community Member, 190 Posts

24 April 2014 at 8:43am

Hi there,

Have any of you worked further on this. I am battling to extend the controller associated with SiteTree. I cant seem to get the form to show on my pages:

_config.php
----------------------------------------
ContentController::add_extension('SidebarEmail_Controller');

SideBarEmail.php
----------------------------------------
class SidebarEmail_Controller extends Extension {

public static $allowed_actions = array (
'EnquiryForm'
);

// ENQUIRY FORM
public function EnquiryForm(){
$fields = new FieldList(
new TextField('Name', 'Your name & surname:'),
new TextField('Tel', 'Your phone number:'),
new EmailField('Email', 'Your email address:'),
new TextAreaField('Comments', 'Your query/comment:'),
new RecaptchaField('MyCaptcha')
);
//Form Action
$actions = new FieldList(
new FormAction('SendContactForm', 'Submit')
);
//Create Validators
$validator = new RequiredFields('Name', 'Email', 'Comments');
//Create form
$form = new Form($this, 'EnquiryForm', $fields, $actions, $validator);
return $form;

}