


The TP framework is updated non-stop, but the use of new projects remains unchanged.
❝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!❞

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!
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」

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 class
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. 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!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.