In-depth analysis of ThinkPHP5 setting template path
This article introduces the method of setting the front-end template path and back-end template path in thinkphp. It has certain reference value. I hope it will be helpful to friends who are learning thinkPHP!
In-depth analysis of ThinkPHP5 setting template path
The default template path is in the module/view file. If you think this is not convenient to manage and want to set it in the Template directory, you can do so.
Template parameters, other parameters that can be affected are the config.php template->view_path parameters under the current module.
Practical operation
(Recommended tutorial: thinkphp tutorial)
1. Configure shared parameters
Set some parameters in apps/config.php to facilitate calling config.php under the Index or Admin module.
apps/config.php, add some parameters.
'template' => [// 模板路径 'view_path' => 'template/', // 就是这里 /** * 前台文件配置 * Author: MR.zhou * */ 'index' => [ // 模快名称 'model_name' =>'index', // 默认模板文件名称 'default_template' => 'default', // 这里可以切换模块下的默认模板名称 ], /** * 后台文件配置 * Author: MR.zhou * */ 'admin'=>[ // 模快名称 'model_name' =>'admin', // 默认模板文件名称 'default_template' =>'default', // 这里可以切换模块下的默认模板名称 ],
2. Set template parameters
index/config.php
'template' => [ // 模板路径 'view_path' => config('template.view_path').config('index.model_name').'/'.config('index.default_template').'/', ],
admin/config.php
<?php //配置文件 return [ // 模板配置 'template' => [ // 模板路径 'view_path' => config('template.view_path').config('admin.model_name').'/'.config('index.default_template').'/', ], ];
3. Setting parameter analysis
The above are the configuration parameters given by others on the thinkPHP official website, but are you unable to display the page correctly according to the above configuration? There are several misunderstandings here that you need to understand. First, view_path =>'template/' in the shared parameter configuration file actually defines the template file as template. However, some people only want to define the template path on the front end, and still use the default view in the background. template method. But such a setting also defines the background template path. How should we solve this problem? The editor below gives two ways to solve the problem of only defining the front-end template path but not the back-end
The first: Do not define the template path in the shared configuration file, but define it in the index module Template path, so it has nothing to do with the background
apps/index/config.php file
'template' => [ // 模板路径 'view_path' => 'template/'.config('index.default_template').'/', ],
Of course, the index configuration file is still defined in my shared configuration file, which is the same as template level, instead of putting it in the template
apps/config.php file
/** * 前台文件配置 * Author: MR.zhou * */ 'index' => [ // 模快名称 'model_name' =>'index', // 默认模板文件名称 'default_template' => 'default', // 这里可以切换模块下的默认模板名称 ],
The second type: Define the template path in the shared configuration file as template, and define the template path in the index module, and redefine view_path in the background =>''
apps/config.php file
/** * 前台文件配置 * Author: MR.zhou * */ 'index' => [ // 模快名称 'model_name' =>'index', // 默认模板文件名称 'default_template' => 'default', // 这里可以切换模块下的默认模板名称 ], 'template' => [// 模板路径 'view_path' => 'template/', // 就是这里
The current background configuration files are as follows
apps/index/config.php文件 'template' => [ // 模板路径 'view_path' => config('template.view_path').config('index.model_name').'/'.config('index.default_template').'/', ],
apps/admin/config.php file
'template' => [ // 模板路径 'view_path' => '', ],
For more thinkPHP tutorials, please pay attention to PHP Chinese website!
The above is the detailed content of In-depth analysis of ThinkPHP5 setting template path. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Detailed explanation of Oracle error 3114: How to solve it quickly, specific code examples are needed. During the development and management of Oracle database, we often encounter various errors, among which error 3114 is a relatively common problem. Error 3114 usually indicates a problem with the database connection, which may be caused by network failure, database service stop, or incorrect connection string settings. This article will explain in detail the cause of error 3114 and how to quickly solve this problem, and attach the specific code

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

Wormhole is a leader in blockchain interoperability, focused on creating resilient, future-proof decentralized systems that prioritize ownership, control, and permissionless innovation. The foundation of this vision is a commitment to technical expertise, ethical principles, and community alignment to redefine the interoperability landscape with simplicity, clarity, and a broad suite of multi-chain solutions. With the rise of zero-knowledge proofs, scaling solutions, and feature-rich token standards, blockchains are becoming more powerful and interoperability is becoming increasingly important. In this innovative application environment, novel governance systems and practical capabilities bring unprecedented opportunities to assets across the network. Protocol builders are now grappling with how to operate in this emerging multi-chain

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.
