A control layer calls the model and the view layer to invoke the model problem?

Source: Internet
Author: User
In a frame, I'm going to be in the view layer OutputData out:

First, in the controller layer, all the data are assembled, the call model call model, and then the view layer template rendering, do not need to read the database, directly with the PHP function output is good.

Second, in the controller layer, simply put the necessary data processing, and then the view layer template rendering, according to the situation and then the database read operations;

Which of these two cases is better?

----------------------Supplement----------------------
My point of view: I think it is irrelevant, because in a controller method introduced a model in, is to say that a file is loaded in, and then in this method to read the data, and finally introduced template file in, then I am in this template file to read the database is also OK, But the former increases the readability and simplicity of the template code. In practical sense there is no big difference ah, do not know this is not the case?

----------------------Supplement----------------------
Know the characteristics of MVC, but see the predecessors have directly in the template to do database query operations, so only to produce such doubts, ask for doubts ~

Reply content:

In a frame, I'm going to output the data in the view layer:

First, in the controller layer, all the data are assembled, the call model call model, and then the view layer template rendering, do not need to read the database, directly with the PHP function output is good.

Second, in the controller layer, simply put the necessary data processing, and then the view layer template rendering, according to the situation and then the database read operations;

Which of these two cases is better?

----------------------Supplement----------------------
My point of view: I think it is irrelevant, because in a controller method introduced a model in, is to say that a file is loaded in, and then in this method to read the data, and finally introduced template file in, then I am in this template file to read the database is also OK, But the former increases the readability and simplicity of the template code. In practical sense there is no big difference ah, do not know this is not the case?

----------------------Supplement----------------------
Know the characteristics of MVC, but see the predecessors have directly in the template to do database query operations, so only to produce such doubts, ask for doubts ~

The first, single duty

Just started to write code, I want to save effort to write database query in the template, a method to solve all problems. It was not until the project ran for two months that the energy savings of the growing block of code would be doubled at this time, and the farther back the project would be, the more it would pay.

Now I'm using第一种

How to say, in fact, each has its own good,
Of course, whether from the specification, or from the development of the project, we recommend the use of the first.

If it is a small project developed by individuals, and there are not too many functions and later extensions, it is quicker to use the second method. Always use, always take

First kind of good! The first one also points to the business logic on M or c. This also varies from person to person.

  • 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.