Jump to:

23483 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Extending DataObject is this the best way?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 804 Views
  • web2works
    Avatar
    Community Member
    50 Posts

    Extending DataObject is this the best way? Link to this post

    Hi, I am looking to create a homepage with feature. The feature will consist of 2 images and a little text. This is the code that I have so far, is kinda works but is there a better way of doing this?

    thanks for any help guys, Ben

    <?php
    class Feature extends DataObject {
       static $db = array(
          'Slogan' => 'Varchar'
       );
       
       static $singular_name = 'Feature';
       static $plural_name = 'Features';
       
       static $has_one = array(
          'Homepage' => 'Homepage',
          'FeatureImage' => 'Image',
          'FeatureText' => 'Image'
       );
    }

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Extending DataObject is this the best way? Link to this post

    Can't see anything wrong with that.

    See this page for more info about DataObjects and DataObject Relation Mananagement:

    http://doc.silverstripe.org/tutorial:5-dataobject-relationship-management

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Extending DataObject is this the best way? Link to this post

    I have it working fine in the backend although I cant seem to use the control in the template to loop through the slogans.
    I have attached the 2 files I have been writing to see if I have dont anything wrong here.

    This is my control obviously with the test data but its not even looping first step:
    <% control Slogans %>
       <li style="background-image: url('{$ThemeDir}/images/media/feature-tv.png');">
          <img src="{$ThemeDir}/images/media/we_make_the_web_beautifully_simple.png" width="" height="" alt="" />
       </li>
    <% end_control %>

    Thanks very much if any body can point me in the right direction.

    Attached Files
  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Extending DataObject is this the best way? Link to this post

    Hi Web2works

    I notice you are using a HasManyCTF, which allows you to select which items to show or hide via checkboxes, only they will be off by default, so make sure you have checked the ones you want to show.

    If you don't need that functonality, I would suggest just using a regular CTF, or even (way way) better is to use the DataObjectManager module and replace the CTF with DOM.

    Aram

    -------------------------------------------------------------------

    www.SSBits.com - SilverStripe Tutorials, tips and other bits

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Extending DataObject is this the best way? Link to this post

    Thanks for that Aram, I will take a good read and play about with the DataObjectManager. I do love SilverStripe I just need to learn how to use it correctly. I bought the book but I have to had the time to read it page by page yet.

    Thanks web2works

    804 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.