How to optimize thinkPHP code

Source: Internet
Author: User
Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it. Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it.

Reply content:

Now I feel that my code is very repetitive. Once the logic is complex, all the code is accumulated together. There is no way to separate them, which is not conducive to maintenance and expansion. How can we optimize it.

If you do not talk about the theory, simply start with php:

  1. We recommend laravel or symfony for learning php open-source projects. Strictly speaking, thinkphp is not object-oriented. The Recommended reason is that the Code is highly componentized (the written code is easy to share and reuse), and the support of various testing tools is very good.

  2. Coverage testing. Common testing frameworks include phpunit, phpspec, behat, and codecept. It is very difficult to write good code at once, and experience needs to be learned from constant optimization. Code that does not write tests cannot be reconstructed. We recommend a simple and clear explanation of how to write a test slide:
    Http://www.slideshare.net/cakper/2014-0407-php-spec-the-only-design-tool-you-need-4developers

  3. Code writing follows the psr1/psr2 code standard https://github.com/pizzaliu/php-fig.

Http://www.zhihu.com/question/35992354

Reading books and improving the theoretical level.

Two books are recommended. Read the first book first and then the second one.

Enterprise Application Architecture Model
Http://book.douban.com/subject/1230559/

Implementation field-driven design
Http://book.douban.com/subject/25844633/

By the way, thinkphp is rarely used. The more skilled thinkphp is, the worse the code is.

First, select the right framework. laravel or yii is a good choice. Second, you think that the code is complex and the logic is repeated, which can reflect that the system architecture is no longer able to meet future business growth. The smelly and long business code should be extracted or independent, make good use of the architecture model or framework.

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.