Home > Backend Development > PHP Tutorial > ThinkPHP模板判断输出Defined标签用法详解_php实例

ThinkPHP模板判断输出Defined标签用法详解_php实例

WBOY
Release: 2016-06-07 17:17:53
Original
837 people have browsed it

ThinkPHP模板引擎的defined标签用于判断常量是否已经被定义
ThinkPHP的defined标签用来判断常量是否已经被定义,其功能相当于PHP中的defined()函数。defined标签用法如下:

<present name="常量">要输出的内容</present>
Copy after login

先在模块操作(如:Index/display )里定义一个常量并输出模板:

define("SITE_NAME", "脚本之家");
$this->display();
Copy after login

在模板/Tpl/default/Index/display.html中使用defined标签如下:

<defined name="SITE_NAME">网站名称:{*SITE_NAME}</defined>
Copy after login

运行该示例会输出:

网站名称:脚本之家
Copy after login

该例子等价的php代码如下:

<&#63;php
if(defined("SITE_NAME")){
  echo '网站名称:',constant("SITE_NAME");
}
&#63;>
Copy after login

如果判断没有被定义,可以使用:

<notdefined name="SITE_NAME">{*SITE_NAME}不存在活未定义</notdefined>
Copy after login

以上两个示例合并之后如下:

<defined name="SITE_NAME">网站名称:{*SITE_NAME}<else/>{*SITE_NAME}不存在活未定义</defined>
Copy after login
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