SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Controller implements document Interface

    Hi guys

    I've been playing around with MVC for quite a while now, eventually I decided to start simple and gradually refactor as I understand more. I think trying to learn too much at once can make things very difficult. So, although my methods are not the most practical at this point in time, it's really helping me to understand.

    At the moment I have a front controller that selects a page controller along with the specific action. The page controller selects the model(s) it needs and parses data to a data array. So each method in the controller would build up the content and then eventually my front controller calls the render function which builds the template using the data array.

    Is this approach ok? To be honest I dont like it as there seems to be a lot of duplicate code in my controllers IE

    $data['keywords'] = 'blah'
    $data['page_title'] = 'blah'
    $data['css'] = 'style'
    $data['javascript'] = 'script'

    Could someone help me improve the way this is done?

    Would it be better to have a "document interface" which my controller would implement or a document object that each controller would use?

    Any help would be much appreciated

    Thanks

    Crabby
    Last edited by crabby80; Oct 17, 2007 at 09:22.

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have duplication, then encapsulate that what doesn't change to remove the duplication, however I don't think that it warrants it's own Interface? If you were to use a separate Interface, to me that suggests that the implementation would need to know how to manipulate that document's data, etc?.

    So you would end up with behaviour in your Controller that may not belong there... Since your Controller would have to implement what the Interface dictates. I think a simple class method alone would suffice

  3. #3
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dr Livingston

    Thanks for reply

    So would it be best just to have a method in my controller such as buildTemplate() to do this?

    P.S great result for rangers!

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > So would it be best just to have a method in my controller such as ...

    I would think so, without seeing an implementation. If at some time in the future you decide that you need to move it out of the Controller, you can do so easily enough via delegation, in that way your client script isn't effect with that refactor.

    Best to keep things simple to begin with.

    Off Topic:

    As for Rangers, yes it's a great result, and for those who don't know enough about Scottish football, Rangers and Celtic are rivals and for one team to get one over the other (in an Old Firm game) is always cause for celebrations.

    Both teams come from Glasgow, and there has been a certain level of religious bigotry in the past but that's on the way out for the most part but it was reason enough for the massive fights after every Old Firm match in the 80s.

    A bit like Man U Vs. Liverpool but more so I suppose

  5. #5
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston View Post
    Off Topic:

    A bit like Man U Vs. Liverpool but more so I suppose
    Off Topic:

    Much more so! I consider it the greatest rivalry in football. And I say this as an Englishman with very little interest in Scottish football.

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    > I consider it the greatest rivalry in football.

    Is that so? Take the rivalry between Man U and Liverpool, multiple it by about 100 and then that should give you an idea of the feeling between Rangers and Celtic fans. Yersterday, I saw someone walking out of Asda's wearing a Celtic top, and I said 'How was the football yersterday?', whilst laughing.

    I got the finger, and told to **** off!! That was that time, another time it actually turned violent. I really wind up the Celtic fans who I come across, and what a laugh it is. On the other hand, if Rangers lose...

    So you see, the greatest rivalry in football is that of between Rangers and Celtic, not even Man U and Liverpool come close, and us Scots do love our football

  7. #7
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston View Post
    Off Topic:


    > I consider it the greatest rivalry in football.

    Is that so? Take the rivalry between Man U and Liverpool, multiple it by about 100 and then that should give you an idea of the feeling between Rangers and Celtic fans. Yersterday, I saw someone walking out of Asda's wearing a Celtic top, and I said 'How was the football yersterday?', whilst laughing.

    I got the finger, and told to **** off!! That was that time, another time it actually turned violent. I really wind up the Celtic fans who I come across, and what a laugh it is. On the other hand, if Rangers lose...

    So you see, the greatest rivalry in football is that of between Rangers and Celtic, not even Man U and Liverpool come close, and us Scots do love our football
    Off Topic:

    Sorry, my post was a little ambiguous. I was referring to the rivalry between Rangers and Celtic.

    Man Utd vs Liverpool doesn't even come close to Swindon Town vs Bristol City! (I'm a Swindon fan btw )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •