Jump to content

"database driven" websites and MVC


sKunKbad

Recommended Posts

Until a couple months ago, I had not even used a framework with MVC. My code was always procedural, and I'm learning more about the benefits of MVC and OOP in general. I practiced by converting my website to the Kohana framework, and about a week ago converted it to CodeIgniter.

 

My question is, while I had not done so, I had assumed that a database driven website meant that views were essentially replaced by plain HTML that is stored in a database, but after thinking more about it, my assumption must be wrong. I can see where product content might be pulled in, through a model , and passed to the view by the controller. Is there ever an instance where a whole view would be stored in the database? Doing so would prohibit the ability to embed php into the views, so I'm guessing this isn't a proper thing to do, but I'm trying to figure out other uses for database driven content (just because I've got nothing better to do on a Friday night). Is it generally slower to have a lot of content coming from the database vs. a file?

 

I got started thinking about this because I have a search on my website, and it is actually using file_get_contents() to look through all of my pages, and due to my website getting a little bigger, this is now starting to be quite a slow search. I thought that perhaps all of my content should belong in the database, and use MySQL to search through for matches. What is the best way to handle searching a website like mine?

Link to post
Share on other sites

Markup can be content.  In the last product I developed we allowed users to customize the markup on certain pages; their custom markup was saved in the database and plugged into the page where appropriate.

Link to post
Share on other sites

Just remember that the primary markup, the markup that you, the developer, controls belongs in the views if you are using MVC.  Anything editable by the user belongs in the database and is inserted as appropriate.

Link to post
Share on other sites

As an example, the posts you've written on this forum are stored in the database, but the files that control how these are represented how they will look are stored on the file system.

 

You could do it the other way around, or store both in the database or both in separate files on the harddisk. However, you need to consider if you actually need the functionality a RDBMS like MySQL offers. Do you need them for the template files? Well, not really. Besides. You do for the posts though. We would like to find posts that belong to a particular topic, in a particular forum, or created by a particular user, or perhaps created within a time interval.

 

Whether you should store something as a file on the disk or in a database depends on your needs.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.