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.

General Questions /

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

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

Extending DataObject is this the best way?


Go to End


5 Posts   1189 Views

Avatar
web2works

Community Member, 50 Posts

14 September 2010 at 9:13pm

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

Avatar
Martijn

Community Member, 271 Posts

14 September 2010 at 9:39pm

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

Avatar
web2works

Community Member, 50 Posts

15 September 2010 at 3:06am

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.

Avatar
Carbon Crayon

Community Member, 598 Posts

15 September 2010 at 3:25am

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

Avatar
web2works

Community Member, 50 Posts

15 September 2010 at 3:32am

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