Home > PHP Framework > ThinkPHP > body text

The TP framework is updated non-stop, but the use of new projects remains unchanged.

咔咔
Release: 2020-08-28 09:53:53
Original
1823 people have browsed it

The framework is constantly being updated, and project implementation needs to move along with it!

##Preface

I built a backend using TP5.0 two years ago and it has been used to this day. It’s not that I don’t want to change, it’s just because of the word “lazy”.

This time I was honored that Kaka needed to write a new project, but I still used the framework I had built before, and stopped as I wrote. Things that have been verified in previous projects can be optimized.

Both in terms of structure and efficiency, it is slowly declining. New things coming out must be for execution efficiency, code style, framework structure, and new functions.

Don’t argue and say it’s just for development efficiency, just stay the same, break the comfort and keep moving forward.

Kaka compiled a roadmap and prepared to write articles according to such a roadmap. Later, I found that knowledge points that were not added are being added. I also look forward to all partners. Let’s help add some information together. See you in the comment area!

The TP framework is updated non-stop, but the use of new projects remains unchanged.
Insert picture description here

1. Framework comparison between 5.0 and 5.1

Don’t argue about why you don’t use 6.0!

First let’s talk about the changes that Kaka experienced in the project , the introduction of facades, class library aliases, model enhancements, annotation routing, middleware.

This is also the most important point for Kaka to optimize. Of course, 5.1 has many new features for 5.0. Just look at the picture!

The TP framework is updated non-stop, but the use of new projects remains unchanged.After using the framework for two years, Kaka still feels that the two most practical functional points in the project are the introduction of facade and middleware.

Continue Next, Kaka will give a brief introduction to the use of facades.

2. Simple and rough understanding of facades

I won’t analyze the principle. Kaka will publish a special article to analyze it later, so when you see this, let’s do it first!

The function of the facade is to prevent a class from instantiating it directly Make static calls.

Comparison of implementation cases using two frameworks

「TP5.0 use」

The TP framework is updated non-stop, but the use of new projects remains unchanged.
Insert picture description here

After introducing the tool class, you need to instantiate it once. When using it later, it will be $ this->session calls methods in the SC class.

This method doesn’t mean it won’t work. Let’s take a look at the effect of TP5.1

「TP5.1 use」The TP framework is updated non-stop, but the use of new projects remains unchanged.The TP framework is updated non-stop, but the use of new projects remains unchanged.After introducing SC , after doing some simple configuration, you can directly and statically call the methods in SC. Isn't this much simpler?

Although the facade setting process is a bit more than the direct instantiation of TP5.0, it is very practical!

"Let's see how to configure the facade of TP5.1"

This is the current project directory structure of Kaka. I define the data namespace in the outer layer. It stores hooks, command line configurations, facade classes, models, service classes, service layers, tool classes, and verification classesThe TP framework is updated non-stop, but the use of new projects remains unchanged.

First of all, we need to make it clear that the SC class is a tool class. So what is a tool class? It is code that can be used in any project. The TP framework is updated non-stop, but the use of new projects remains unchanged.Then you need to inherit the facade classThe TP framework is updated non-stop, but the use of new projects remains unchanged.There cannot be only one facade class in a project. There are many that we can register as facade classes for easy use.

So you need to write a hook, in which all classes that need to be registered to the facade are registered, and aliases can also be given. The TP framework is updated non-stop, but the use of new projects remains unchanged.As you can see in the picture above, Config is used to load a configuration file, so the configuration file is definitely indispensable.

Register our SC class file into the configuration file. The TP framework is updated non-stop, but the use of new projects remains unchanged.There is still one last step to go. Have you ever thought about it? The hook is defined but not executed!

At this time, directly configure the hook file to be loaded when the application is initialized.

The TP framework is updated non-stop, but the use of new projects remains unchanged.The facade is configured until here. When using it later, just use SC:: to call the method.

Persistence in learning, persistence in blogging, and persistence in sharing are the beliefs that Kaka has always adhered to since his career. I hope that Kaka’s articles in Nuoda Internet can bring you Any help. See you next time.

The above is the detailed content of The TP framework is updated non-stop, but the use of new projects remains unchanged.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!