NikkiLoveGod Posted November 12, 2008 Share Posted November 12, 2008 Hi all! I am having some trouble figuring out the MVC thingy. There is a couple of things that keep bothering me. Mainly about templates. How do I implement different "views" of the same "category". Like I have a news module in my site, and in the news module, I need to list, add and edit news. So that is 3 different views. So, I have situation where I have a frontController, that assigns a pageController, in this situation newsController. The FrontController also assigns newsView. newsController makes the newsView load the layout template. Now it is time to add the "specific template", like add_news, edit_news and so on. So should I create each "view" a separate template file in a "news" folder for example? Or should I have one template file for news, and have a check there what to show? So that way, I will have like a billion different files on a rather small site. It feels rather strange, as I have always had just one file, and in there I have had like an switch case to put up a different view. How is these things done normally? I couldn't figure out from Zend FW nor CodeIgniter. Explanation is very welcomed! Thanks! -NikkiLoveGod Quote Link to comment Share on other sites More sharing options...
Mastodont Posted November 12, 2008 Share Posted November 12, 2008 I need to list, add and edit news. So that is 3 different views. This is one presentation view and one view with form, IMHO. So should I create each "view" a separate template file in a "news" folder for example? Yes, because you can easily edit templates this way. Quote Link to comment Share on other sites More sharing options...
NikkiLoveGod Posted November 12, 2008 Author Share Posted November 12, 2008 Thanks for a quick reply there Mastodont! So, in newsController I control wether to show the presentation view, which is the listing, and then the add_edit_news view. Then at controller I assign different variables to use at the form action url, and use empty variables to populate the form when just adding a new, and when editing i just give the variables some value. Or should I have some check there whether the variables are set, then echo them? Does empty variables give a security issue, as they raise a php warning? Then how about if I have some small "info" things, like "Thank you for adding the news!", and I would like them to appear like in front of the "add_edit_news" view. Should I have a separate view for that too? I dont want to copy the add_edit_news view inside this one, so that I dont have to update two things, which is the whole point in these. Thanks again! Sorry to ask "stupid" questions, and make people explain things like to a 5 year old kid Quote Link to comment Share on other sites More sharing options...
Mastodont Posted November 13, 2008 Share Posted November 13, 2008 Then at controller I assign different variables to use at the form action url, and use empty variables to populate the form when just adding a new, and when editing i just give the variables some value. Or should I have some check there whether the variables are set, then echo them? There are many ways you can go. Try yourself. I have separate class for form processing and templates with placeholders for individual fields. These placeholders are either deleted (add form) or replaced with current values from table (edit form). small "info" things, like "Thank you for adding the news!", and I would like them to appear like in front of the "add_edit_news" view These things can be also solved by placeholders in template. You have only to track the state of the form and fill or delete placeholders. Or you can have separate messages and send them instead of form. Quote Link to comment Share on other sites More sharing options...
NikkiLoveGod Posted November 13, 2008 Author Share Posted November 13, 2008 Thank you, yet again Mastodont. I'll go with these! Quote Link to comment 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.