Home >Backend Development >PHP Tutorial >Confused about frame page output and method output in the page call controller?
The place in the red circle on the right is the PHP
code for data manipulation on the page. It has more than 100 lines, and the same code block is also used in other places. Maybe it is different in a few places. At this time, someone may ask, why not encapsulate such a large block of code and call it multiple times on different pages? Doubts Right here, is it efficient to perform data operations directly on the page or call methods in the controller on the page to perform data operations?
Here is a code block for data judgment, which is to judge whether the data is qualified. There may be many pieces of data. If I call the method in the controller, won't it have to be called dozens of times?
The place in the red circle on the right is the PHP
code for data manipulation on the page. It has more than 100 lines, and the same code block is also used in other places. Maybe it is different in a few places. At this time, someone may ask, why not encapsulate such a large block of code and call it multiple times on different pages? Doubts Right here, is it efficient to perform data operations directly on the page or call methods in the controller on the page to perform data operations?
Here is a code block for data judgment, which is to judge whether the data is qualified. There may be many pieces of data. If I call the method in the controller, won't it have to be called dozens of times?
Regarding your doubts: There is no efficiency problem, the execution efficiency is the same everywhere
Regarding your code itself: Dear, you can use static methods to seal this kind of thing anywhere, but it is not recommended. To put it in the controller, it is best to write a helper specifically.
Well, if you were in my hands, you wouldn’t be able to pass the test just based on the length of the code in the thumbnail.
Encapsulation is important, but encapsulating it in the right place is even more important.