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.PHP
Code. 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.PHP
Code. 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.