Shouldn’t queries be executed in a view?

Asked

Viewed 22 times

0

I ended up reading this little "It is important to note that queries should not be executed in a view. The correct thing is that you apply a MVC Pattern( Model View Controller) and separate things. A good example, using the Code Framework Igniter" Can anyone explain me better, and what’s the difference of running the query in the view? And if I should change my project because of it

  • Voce executes querie in your views ?

1 answer

0


As per standard MVC your queries should be executed by the layer Model. The MVC is a very popular and widely applied standard these days. It is a standard and can be replaced by others.

However it is strongly recommended that if you follow any pattern, that way if someone else maintains your code you will have a little less difficulty understanding it yourself.

Aligned with MVC it is interesting to follow other good programming practices, such as: DRY, SOLID and others.

Best practices serve to make our codes more human-readable, thus facilitating maintenance and increasing the project lifecycle.

The big difference in the place where the query is executed is in the project organization.

As for the question of changing the project, I think only you can answer that.

If you are free to restart the project, I recommend you look at the Laravel, which is a php framework that applies MVC. I recommend it for the wide community membership and ease of finding material.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.