Thinkphp optimization Summary-PHP development

Source: Internet
Author: User
Some time ago I wrote a blog program wblog using the thinkphp framework, and then optimized it. Now I feel the strength of the thinkphp framework. In the early stage, wblog had many thinkphp features that were useless. It was based on the idea of developing the original php system. Thinkphp is a framework based on the MVC model. Generally, the business is processed on M (model), and C (Controller) only responsible for organizing the call of M processed function to return it to V (view ). However, some time ago, in order to write a blog, I used thinkphp framework to write a blog program wblog, and then optimized it. Now I feel the strength of thinkphp framework.

In the early stage, wblog had many thinkphp features that were useless. It was based on the idea of developing the original php system. Thinkphp is a framework based on the MVC model. Generally, the business is processed on M (model), and C (Controller) only responsible for organizing the call of M processed function to return it to V (view ). However, C in the previous WBLOG seems to shoulder two tasks: business processing and organization control, which violates the MVC philosophy. For example, place all functions in the public controller CommonAction. class. in php, the rest of the controllers inherit from the public controller, because there are too many functions, so CommonAction. class. php seems a little swollen, while the Model is idle and does nothing.

This time, WBlog was optimized. Each table corresponds to a Model, which is responsible for processing the related logical business. The Controller is responsible for organizing and controlling the business processed by the Model. In the previous section, "How to completely delete the tag of the thinkphp3.1 case blog? "I wrote a method to delete a tag. At the beginning, this method was put on the controller. Now we put it on the model and compare it.

The following delete function is written on the public controller CommonAction. class. php.

Public function deltag ($ recordId) {$ condition ['recordid'] = $ recordId; // get the ID of the diary $ tagged = M ('taged '); $ taggedlist = $ tagged-> where ($ condition)-> select (); // select is used instead of find, because a diary may have multiple tags $ taggedids = array (); // declare an array to hold think

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.