curiousgeorge
curiousgeorge

Reputation: 361

MVC good or bad practice

I am working on my first MVC application in PHP (CodeIgniter framework). Let's say I have 2 controllers: Cont1 and Cont2

Cont1 is associated with the MySQL table 'cont1' and Cont2 is associated with table 'cont2'

In my Cont2 model, every time I have to insert a new entry in my cont2 table I have to update a field in cont1 (they're relational tables).

Is it considered a bad practice if I execute a MySQL query in the model of Cont2 to update a table that is associated with the model of Cont1? Are there any good MVC approaches to this problem?

Upvotes: 0

Views: 630

Answers (2)

davzie
davzie

Reputation: 116

I usually have one controller, a page controller, and another, an admin controller.

I then have a "news" library for example and that library calls functions from the "news" model.

The functions in here allow me to add news, delete it, edit it but it also allows me to pull news from the database and display it on the website.

So I can use that library in both my admin controller and page controller. So controllers aren't associated with actual database tables. My news model utilises several other libraries that upload images and data into other tables in the database and your method is as a result perfectly fine.

Upvotes: 0

Gordon
Gordon

Reputation: 317197

Controllers are not associated to tables, nor is your Model just the Database, nor is Code Igniter's definition of ActiveRecord correct. Apart from that it is okay to update whatever needs updating from within the Model.

Upvotes: 3

Related Questions