Multiple Views or db records


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)

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,


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.

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.

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.

Thanks again.
I'l go play with it now and see if I can make it happen in a real world environment.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.