Welcome Guest, Not a member yet? Register   Sign In
Is conceptually correct to access DB from Controller?
#1

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?

Dodgy
Recovering the wasted time...
Reply
#2

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
Reply
#3

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...
Reply
#4

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.
Reply
#5

(04-25-2020, 01:21 PM)jreklund Wrote: But you are technically breaking MVC

Cool, thanks, I just wanted to be sure that I wasn't fantasying!

Big Grin
Recovering the wasted time...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB