redbullmarky Posted May 23, 2007 Share Posted May 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/ Share on other sites More sharing options...
steelmanronald06 Posted May 23, 2007 Share Posted May 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-259962 Share on other sites More sharing options...
redbullmarky Posted May 23, 2007 Author Share Posted May 23, 2007 possibly, though i'm trying to keep any form of HTML generation (bar things like BBCode, Smilies, etc) out of my controllers/libraries/helpers, etc. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-259968 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-259990 Share on other sites More sharing options...
redbullmarky Posted May 23, 2007 Author Share Posted May 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-259999 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-260008 Share on other sites More sharing options...
redbullmarky Posted May 23, 2007 Author Share Posted May 23, 2007 so would you say then that it's ok (best practice) for the view (be it directly from a template or via a helper) to have access to the model? or is that just the way you'd personally do it? Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-260020 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-260095 Share on other sites More sharing options...
utexas_pjm Posted May 23, 2007 Share Posted May 23, 2007 stupid Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-260133 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 Hey, I didn't mean that literally! Quote Link to comment https://forums.phpfreaks.com/topic/52659-news-cms-the-tidiest-way/#findComment-260145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.