Home > Backend Development > PHP Tutorial > thinkphp模板赋值与替换实例简述_PHP

thinkphp模板赋值与替换实例简述_PHP

WBOY
Release: 2016-05-31 18:15:39
Original
963 people have browsed it

本文实例讲述了thinkphp模板赋值与替换方法。分享给大家供大家参考。具体实现方法如下:

1. 模板中的赋值方法:

代码如下:

$this->assign('name','');//第一种赋值方法 
$this->name='jb51';//第二种动态赋值方法 
$this->display();


2. 模板替换方法:

PUBLIC__:会被替换成当前网站的公共目录,通常是 /thinkphp/Public/;在Public中建立Css文件夹,建立basic.css文件

__ROOT__:会替换成当前网站的地址(不含域名) /thinkphp

__APP__:会替换成当前项目的URL地址(不含域名)  /thinkphp/index.php;

__GROUP__:会替换成当前分组的URL地址(不含域名)  /thinkphp/index.php/Index;

__URL__:会替换成当前模块的URL地址(不含域名)  /thinkphp/index.php/Index/index;

__ACTION__:会替换成当前操作的URL地址(不含域名)/thinkphp/;

__SELF__:会替换成当前的页面URL

更换模板变量规则,修改配置项

代码如下:

'TMPL_PARSE_STRING'=>array(           //添加自己的模板变量规则 
'__CSS__'=>__ROOT__.'/Public/Css',  //指定文件存放目录 
'__JS__'=>__ROOT__.'/Public/Js', 
    ),


调用方法:

代码如下:

href='__CSS__/basic.css' href='__JS__/basic.css'

希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template