search
HomePHP FrameworkThinkPHPThe 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!

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!

Statement
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
What Are the Key Features of ThinkPHP's Built-in Testing Framework?What Are the Key Features of ThinkPHP's Built-in Testing Framework?Mar 18, 2025 pm 05:01 PM

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.

How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds?How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds?Mar 18, 2025 pm 04:57 PM

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

What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?Mar 18, 2025 pm 04:54 PM

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

How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices?How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices?Mar 18, 2025 pm 04:51 PM

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

What Are the Advanced Features of ThinkPHP's Dependency Injection Container?What Are the Advanced Features of ThinkPHP's Dependency Injection Container?Mar 18, 2025 pm 04:50 PM

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

How to Use ThinkPHP for Building Real-Time Collaboration Tools?How to Use ThinkPHP for Building Real-Time Collaboration Tools?Mar 18, 2025 pm 04:49 PM

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

What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications?What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications?Mar 18, 2025 pm 04:46 PM

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

How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ?How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ?Mar 18, 2025 pm 04:45 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

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 new version

SublimeText3 Linux latest version

Safe Exam Browser

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

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.