Jump to content

News CMS, the tidiest way


Recommended Posts

Hi all

Just after some ideas. I'm looking at setting up a module for my framework that will support different sorts of articles in a flexible layout.

 

Consider this page: http://news.bbc.co.uk/ - this is ideally what I'd like.

 

My only issue is when I've tried "MVCing" the bits and pieces to pull a page like this together, my templates do kinda get cluttered with tonnes of PHP code (mostly "view" logic like foreach's and echos etc, but still - it looks more PHP than HTML). If it was just a simple, 1 column list of articles, it wouldnt be an issue - just a standard foreach - but I wanna move on from that.

 

I've also considered the idea of having a "grid" (prob made of a TABLE, for argument sake), each cell would echo a variable containing the article's HTML. But in terms of MVC, this would mean that my controllers would be handling too much in terms of the way the page looks.

 

I'm not interested in other technologies (XML/XSLT, etc) at this point - I'd just like to get a few ideas of how i might tackle this. Im one of my sites, I've gotten something along the same lines: http://www.holdingthebaby.com/articles/dads/ although it's not as busy and not as flexible, and even THIS one uses a good chunk of PHP in my templates.

 

Any thoughts?

Cheers

Mark

 

Link to comment
Share on other sites

would it not be easier to build a set of functions in your class and then on the view pages have those functions called?  and then in the functions you have how it should appear (is it okay to have html in your controllers/models?) and so all you need to do on the view page is call that function.

Link to comment
Share on other sites

I re-glanced over PoEAA's Template View chapter.

 

Basically Fowler offers the following choices:

 

1) Use custom tags (basically this will create a new language)

2) Nest code in HTML (which you are already doing)

3) Move loops, conditionals and the outputting of HTML dependent on them into Helper (Ronald more or less suggested that, Fowler seems to favor this)

 

I know that may not help very much. It's just not that easy. Sorry.  :P

Link to comment
Share on other sites

ok cool. I guess the only thing i see with helpers is that they're not really part of the template. Aside from seperation that MVC gives, I guess I kinda subscribed to the logic that templates were supposed to be predominantly HTML wheras when i employ helpers, I'm essentially introducing code into the template and HTML into the code (ie, HTML into the helper). I don't have any major issues with this (in fact, doing the page itself isn't really the problem) - the issues I guess come when trying to do things the "right way" which has so far served me well in terms of making changes.

 

oh well. Helpers prob the way to go - possibly something like <?=$article->render($articledata) ?>  and <?=$article->renderList($articles) ?> - unless i'm missing something easier/cleaner.

 

put it this way - as long as it's easy to maintain, easy to use and easy to re-skin without sifting through clumps of logic and code, I'm sold even if i break a rule or two.

Link to comment
Share on other sites

I do something like this: (partly) mimic the model's hierarchy, and take a model argument. Example:

 

$newsItem = new View_NewsItem(new Model_NewsItem($id));
...
echo $newsItem;

 

These helpers are part of the View because they deal with presentation of model data only.

 

Link to comment
Share on other sites

Well, the description of MVC does describe Controller and View to have equal oppurtinity to access the Model. That said, I usually only provide the View with the part of the Model it will need. The Controller does that. The alternative is for the View to have global access to the model, via for example a global Registry, but I tend to avoid that if possible.

 

Basically the View Helpers that handle representational tasks only ensure that the View has read-only access to the model. Whether they are part of the View or the Model is open for interpretation. My interpretation says they are part of the View.

 

You know there is not one 'best practice', one 'right way'. I like this way, someone else might call me stupid for it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.