Using ORM classes directly from the controller in MVC, bad practice?

前端 未结 4 2002
抹茶落季
抹茶落季 2021-01-12 13:06

I\'ve recently delved into using an ORM in my CodeIgniter application and one i\'ve gone for is Propel. Now this gives me the power to basically use Propels classes as the \

4条回答
  •  被撕碎了的回忆
    2021-01-12 13:35

    Yes, it's bad practice.

    The model should contain all of your data logic and abstract it all away from the rest of the program. To the rest of the application, the models should look like black boxes out of which it gets its data. If you use an ORM as your model, you're leaking the abstraction and tightly coupling your controller to your data layer.

    Instead, create your models, and deal with the ORM in there. That way if you ever need to adjust your data model, you can just change it in one place (the model layer) and know that the abstraction will hold.

提交回复
热议问题