Ask me a question about mvc. I am a newbie. I am studying ci 3.x by myself. I recently encountered a question in my practice and would like to ask:
The specific situation is that I want to create a video vod, and the homepage will display the latest 10 movies (10 records). my idea is to write a controller c_main output view v_main, I would like to ask where to put the query operations on the database? Whether to directly execute the select statement in the controller or write a model m_main to query the database in the model, instead of loading the model in the controller.
I would like to ask you if, under normal circumstances, all kinds of operations on the database only in the model are more in line with the mvc requirements ???
Reply to discussion (solution)
M generally implements business logic
C. hand over the processed result from M to V.
Therefore, you should query the database in the m_main model.
Now that you are using CI 3, you should follow his agreement.
Generally, database operations are performed in the model. C call is passed to V. Of course, writing directly in C is also acceptable.