This article mainly introduces ThinkPHP template replacement and system constants and applications. It is a very important concept. Friends who need it can refer to it.
This article describes ThinkPHP template replacement, system constants and applications. It is ThinkPHP It is necessary to have a firm grasp of the basic knowledge of project development. The details are as follows:
Default template replacement rules:
../Public: will be replaced by the public template directory of the current project, usually /project directory/Tpl/ default/Public/
__PUBLIC__: will be replaced by the public directory of the current website, usually /Public/
__TMPL__: will be replaced by the project's template directory, usually /project directory/Tpl/default/
__ROOT__: Will be replaced with the address of the current website (excluding domain name)
__APP__: Will be replaced with the URL address of the current project (excluding domain name)
__URL__: Will be replaced with the URL address of the current module (excluding domain name)
__ACTION__: Will be replaced by the URL address of the current operation (excluding domain name)
__SELF__: Will be replaced by the current page URL
You can also customize the replacement rules by configuring the value of TMPL_PARSE_STRING in the project configuration file , such as:
TMPL_PARSE_STRING => array( '__PUBLIC__' => '/Common' , // 更改默认的 __PUBLIC__ 替换规则 '__UPLOAD__' => '/Public/Uploads/' , // 增加新的上传路径替换规则 )
Example:
File path:/Home/Tpl/default/User/index.html, code As follows:
<p>__ROOT__代表当前网站的网址</p> <p>__URL__代表当前模块的URL地址/index.php/User</p> <p>../Public代表/aoli/Tpl/default/Public</p> <p>__PUBLIC__代表项目公共文件目录/Public</p> <p>__TMPL__代表当前项目的模板目录/aoli/Tpl/default/</p> <p>__APP__代表当前项目的入口文件地址/index.php</p> <p>__ACTION__代表当前的操作地址/index.php/User/index</p> <p>__SELF__代表当前URL地址/index.php/User/</p> <p>__UPLOAD__</p> <form action="__URL__/add" method="post"> <input type="text" name="username" /> <input type="submit" value="注册" /> </form>
File path:/Home/Lib/Action/UserAction.class.php, the code is as follows:
<?php class UserAction extends Action { function index(){ $this->display(); } function add(){ dump($_POST); } } ?>
Related recommendations:
Methods for mutual calls between ThinkPHP controllers
The above is the detailed content of ThinkPHP template replacement and system constants and application examples. For more information, please follow other related articles on the PHP Chinese website!