What is path replacement
Using specific variables to replace paths is to make it more convenient and flexible during thinkphp development and debugging. Path replacement in thinkphp is mainly implemented through three variables, namely __APP__, __PUBLIC__ and __ROOT__.
The variable __APP__ represents the directory containing the index.php file, which is the root directory of the application. Taking the default settings as an example, using __APP__ instead of the path can generate the following path:
"/home/wwwroot/default/ThinkPHP/Application/"
__PUBLIC__ The global variable refers to the path of the public directory, that is, it is deployed to the public directory under the root directory of the website. For example, you can use the following code to get the path to the public directory:
"/home/wwwroot/default/test/public/"
Indicates the directory where the entire application is located is the __ROOT__ variable, which represents the root directory of the application. Here's one way to rewrite it: By default, using "__ROOT__" alternative path can achieve path simplification
"/home/wwwroot/default/ThinkPHP/"
How to perform path replacement
In thinkphp, you can use the configuration file or in the code Use variables directly for path replacement.
Use configuration files for path replacement
In thinkphp, you can edit the config.php configuration file to perform path replacement. The specific steps are as follows:
-
Open config. php configuration file, find the following code:
<code>return array(<br/> // ...省略其他配置代码<br/> // 项目相关配置<br/> 'TMPL_PARSE_STRING' =>array(<br/> '__PUBLIC__' => '/public',// 更改默认的/Public 替换规则<br/> '__ROOT__' => '', // 更改默认的/ 替换规则<br/> '__APP__' => '/Application/', // 更改默认的/App 替换规则<br/> ),<br/> // ...省略其他配置代码<br/>);<br/></code>
- ##Modify the corresponding values of __PUBLIC__, __ROOT__, __APP__ , for example, change it to the following code:
<code>return array(<br/> // ...省略其他配置代码<br/> // 项目相关配置<br/> 'TMPL_PARSE_STRING' =>array(<br/> '__PUBLIC__' => '/static',// 将/Public替换为/static<br/> '__ROOT__' => '', // 根目录不变<br/> '__APP__' => '/app/', // 将/App替换为/app/<br/> ),<br/> // ...省略其他配置代码<br/>);<br/></code>
##Save the changes and use __PUBLIC__, __ROOT__ in the code , __APP__ performs path replacement.
Using variables in the code to perform path replacement is another feasible method, which is not limited to Used for path replacement in configuration files. Taking __PUBLIC__ as an example, you can use the following code for path replacement:
<?php // 在php文件中,可以使用变量__PUBLIC__来代替public目录的路径 require __PUBLIC__ . '/css/style.css'; ?>
The above is the detailed content of How to implement path replacement in thinkphp. 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

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.