ThinkPHP路径标签基础与示例
本实例深入探讨了ThinkPHP中常用的路径处理机制,旨在为开发者提供实用的参考指南。
文中重点梳理了以下核心标签:__root__、__self__、__action__、__url__、__app__以及__public__。
设定项目首页访问地址为:www.test.com/other/Form。
假设当前处理的模块名称为:Index。
假设当前执行的操作方法为:index。
在此配置下,首页的完整URL结构为:http://www.test.com/other/Form/index.php/Index/index。
1 __ROOT__:解析结果为 /other/thinkphp/mydemo。
2 __SELF__:解析结果为 /other/thinkphp/mydemo/Form/index.php。
3 __ACTION__:解析结果为 /other/thinkphp/mydemo/Form/index.php/Index/index。
4 __URL__:解析结果为 /other/thinkphp/mydemo/Form/index.php/Index。
5 __APP__:解析结果为 /other/thinkphp/mydemo/Form/index.php。
6 __PUBLIC__:解析结果为 /other/thinkphp/mydemo/Public。
7 ../public(不区分大小写):解析结果为 /other /thinkphp/mydemo/Form/Tpl/default/Public。
8 APP_PUBLIC_URL:解析结果为 /other/thinkphp/mydemo/Form/Tpl/default/Public。
9 WEB_PUBLIC_URL:解析结果为 /other/thinkphp/mydemo/Public。
模板引擎对路径部分的替换逻辑如下所示: 复制代码 代码如下://项目公共目录 $tmplContent = str_ireplace('../public',APP_PUBLIC_URL,$tmplContent); //网站公共目录 $tmplContent = str_replace('__PUBLIC__',WEB_PUBLIC_URL,$tmplContent); //网站根目录 $tmplContent = str_replace('__ROOT__',__ROOT__,$tmplContent); //当前项目地址 $tmplContent = str_replace('__APP__',__APP__,$tmplContent); //当前模块地址 $tmplContent = str_replace('__URL__',__URL__,$tmplContent); //当前项目操作地址 $tmplContent = str_replace('__ACTION__',__ACTION__,$tmplContent); //当前页面操作地址 $tmplContent = str_replace('__SELF__',__SELF__,$tmplContent);
希望上述关于ThinkPHP框架路径标签的解析内容,能对从事PHP程序设计的开发人员有所助益。