Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » A question of style.

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

Page: 1
Go to End
Author Topic: 828 Views
  • meganub
    Avatar
    Community Member
    15 Posts

    A question of style. Link to this post

    Hi!

    I'm fairly new to SilverStripe, but not to OO PHP5 or development in general. Firstly, from what I've seen so far I'm really liking SilverStripe.

    I am currently using it to build a site wherein most of the pages that need to be under CMS control are pretty much identical to the base Page class. I.e. A title and a big rich text field is all that's needed.

    However, the look and feel of some of these pages is radically different, hence they need different templates.

    Now there seems to be two options (possibly more, but like I said, I'm new) for me to get the different templates working for these different, but similar pages.

    1) I can just put a switch statement in the index action function within PageController and test something unique to each instance and then apply different templates.

    I.e.

    Switch (UniqueThing) {
    case '1':
    use template A;
    ...
    case 'n':
    use template N;
    }

    2) Create a different sub page class for each unique page design and let that call the required template automatically. I.e. HomepagePage, ArticlePage, TermsPage etc etc.

    I can see minor pro's and con's with either approach. I just wanted to ask the forum which way would be considered the 'SilverStripe way'?

    Cheers in advance!

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: A question of style. Link to this post

    2.) definitely. That's how we typically create projects using SilverStripe.

    Polymorphism is better than a lot of switch or if statements.

    Sean

  • banal
    Avatar
    Community Member
    901 Posts

    Re: A question of style. Link to this post

    Yes, I second what Sean said!
    Creating different classes doesn't create a lot of overhead (actually just a new entry in the ClassName enum) and you're still free to extend a given page-type later on... much cleaner and easier to extend.

  • meganub
    Avatar
    Community Member
    15 Posts

    Re: A question of style. Link to this post

    Thanks guys! Really prompt and helpful.

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