Is conceptually correct to access DB from Controller? |
This is more a conceptual question. I am learning MVC and I recently watched a video that supposed to show how to implement a simple CRUD by using the basic query builder methods. Everything was doing well when he called the method save() directly from the Controller.
Maybe I just didn't get correctly the philosophy behind the MVC but it looks totally odd to me. What am I missing here?
Recovering the wasted time...
If it's the Models save() function it's indeed correct. You trigger Models from Controllers, but should not use the query builder itself in Controllers.
You can read more about it in the userguide: https://codeigniter.com/user_guide/concepts/mvc.html
Nope, he was using the query builder save method.
As I imagined the guy was doing it wrongly. Thanks for the answer!
Recovering the wasted time...
There are nothing in the code that's stopping you of doing so. If you need to access one table, only ones, in an controller. It may be just worth it. But you are technically breaking MVC, but I have done it for small things.
|
Welcome Guest, Not a member yet? Register Sign In |