tags:

views:

406

answers:

1

Hi

I understand what is MVC and CMS. I understand MVC pattern and how CMS should working. But I have problem with theming and the pattern.

Example:

When CMS is installed on serwer I want to change my homepage. I want to display some additional data. I change my homepage template and add a function call to pull data from DB. My new data will be displayed on my homepage. :)

But when I do this I broke MVC pattern because in this situation View decide which data should be read from DB to display on my homepage.

So... is it MVC for a CMS? Or maybe it shouldn't be a clear MVC pattern to work with situations like this? Maybe I should forget about patterns? I'm confusing...

PS Wordpress it's not build on MVC pattern, I guess?

A: 

Design patterns like MVC are meant to be about separating your display code from the business logic, etc. This makes it easier to change any part without affecting any of the other parts (eg. change the templates without having to worry about accidentally changing any business logic).

You situation sounds like the function you are adding is simple view logic? It might be best to put the function into a Helper and have the helper call for the data through a Model. Then, in your view, just call the Helper.

In pseudocode:

Helper

function get_whatever_data () {
    // get the actual data from the model
    return SomeModel.get_the_data_thats_needed_here()
}

View

<div id="some-id">
    <? print get_whatever_data() ?>
</div>
Nathan