Ask a question about mvc-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.