Multiple Views or db records - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Multiple Views or db records (/showthread.php?tid=30997) |
Multiple Views or db records - El Forum - 06-02-2010 [eluser]PG-Tips[/eluser] Hi, I'm new to MVC and Codeigniter and am wondering about a best practice and if anyone can advise. As an example, I have three pages, which have content stored in a db. -About us -Contact (with HTML form and response) -News Before CI and MVC I would likely only have had one HTML view and I would have either stored some HTML in a db record or would have built some HTML on the fly in my functions page. As I understand MVC, the idea is to have HTML only in the views pages, (correct?) but doing so for the above means I end up with 3 views pages instead of one, and as the differences between the pages are trivial in terms of formatting this seems like a lot of updating to do if ever I need to modify my page appearances. So the question is, is it correct/better to have lots of view pages than to do a bit of HTML generation in the controller or store HTML in the database? I find it hard to see any advantage in the example above, but the term MVC would suggest that it is. Many thanks, Pat Multiple Views or db records - El Forum - 06-03-2010 [eluser]mddd[/eluser] The idea of not putting html in a controller or model is valuable, because it makes managing the application easier. In principle, a designer should be able to change the design of the site by only working in the views folder. That's why it is better not to build tables inside a model, etc. But this doensn't mean that all your content has to be in a view. There can be a difference between the html of your site layout, and the html that is the real content of your site. Imagine a site with 100 000 pages.. they can never be all views. They should be in a database! So, html-content in the database - fine. Building pieces of html in a model or controller - not so fine, because it makes maintainance harder. Multiple Views or db records - El Forum - 06-03-2010 [eluser]PG-Tips[/eluser] Thanks for the succinct reply - makes sense. In a real world example then, if I had an Emailing Subscribe page would I put the code and content for the form directly in a View but for an About us page, insert the copy into the view via the Model/Controller? I appreciate there must be many gray areas, but is that the general practice? Thanks again. Multiple Views or db records - El Forum - 06-03-2010 [eluser]mddd[/eluser] Yes I think that is correct. A form needs some php code in it, to show errors etc. So that will be hard to do in the database. And you can always make a combination if necessary. If there is some text on the page that you'd like to store in the database (maybe because it can then be edited through a cms) you can load that content from the database and display the form below it by loading a view. Multiple Views or db records - El Forum - 06-03-2010 [eluser]PG-Tips[/eluser] Thanks again. I'l go play with it now and see if I can make it happen in a real world environment. |