❝The framework is constantly being updated, and project implementation needs to move along with it!
❞
❝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!❞
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!
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.
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」
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」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 classes
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. Then you need to inherit the facade classThere 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. 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. 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 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!