Are there any questions about the framework page output and the method output in the page call controller? -Php Tutorial

Source: Internet
Author: User
The place in the red circle on the right is the PHP code for data operations on the page. there are more than 100 lines, and the same code block is also useful in other places, maybe in a few places. At this time, someone may ask why such a large block of code is called multiple times on different pages...

The place in the red circle on the right is the data operation on the page.PHPCode. there are more than 100 lines of code, and the same code block is also used in other places. maybe there are several different places. At this time, someone may ask why such a large block of code is not encapsulated and called multiple times on different pages?DoubtHere, the efficiency of directly performing data operations on the page and calling methods in the controller on the page is a problem?

Here is a data judgment code block, that is, to determine whether the data is qualified. There may be a lot of data. if I call a method in the controller, wouldn't I have to call dozens of times?

Reply content:

The place in the red circle on the right is the data operation on the page.PHPCode. there are more than 100 lines of code, and the same code block is also used in other places. maybe there are several different places. At this time, someone may ask why such a large block of code is not encapsulated and called multiple times on different pages?DoubtHere, the efficiency of directly performing data operations on the page and calling methods in the controller on the page is a problem?

Here is a data judgment code block, that is, to determine whether the data is qualified. There may be a lot of data. if I call a method in the controller, wouldn't I have to call dozens of times?

Your doubts: no efficiency problems, where the execution efficiency is the same
For your code itself: you can store this type of code in a static way, but it is not recommended to write a Helper in the controller.
Alas, if you are under my hands, you will not be able to close the line by the code length in the thumbnail.
Encapsulation is important. encapsulation to the right is more important.

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.