Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Best Practices Extending SiteTree

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

Page: 1
Go to End
Author Topic: 436 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Best Practices Extending SiteTree Link to this post

    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?

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Best Practices Extending SiteTree Link to this post

    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.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Best Practices Extending SiteTree Link to this post

    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

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: Best Practices Extending SiteTree Link to this post

    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;
          
    }

    436 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.