search
Homephp教程php手册thinkphp模板赋值与替换实例简述

这篇文章主要介绍了thinkphp模板赋值与替换的方法,以实例形式简述了模板复制的两种简单方法,以及模板替换中的特殊字符串说明与用法实例,是使用频率比较高的技巧,

本文实例讲述了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框架程序设计有所帮助。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function