(thinkphp6开发手册)(thinkphp5.1开发手册)

上一篇文章讲解“模型-内置标签之条件标签一”,本篇文章讲解“模板-内置标签之条件标签二”。

接上一篇文章

三、范围判断

范围判断标签包括in/notin/between/notbetween四个标签,都用于判断变量是否中某个范围。

1. IN和NOTIN

(thinkphp6开发手册)(thinkphp5.1开发手册)

1)基本使用

①在Index控制器中,新建intag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在in.html模板中使用in和notin标签进行判断

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

2)in与notin标签合并效果

in标签与notin标签合并,即成为in...else效果。

在in.html模板中将in与notin标签合并使用:

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

3)name属性支持系统变量

在in.html模板中,name属性判断系统变量:

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

4)value属性使用变量

①在Index控制器中,修改intag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在in.html模板中,使用in标签判断,并且标签的value属性使用变量

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

注意:

1. value属性的值可以是用逗号分隔的字符串、数组、系统变量。

2. value属性的值使用变量时,要加“$”,不加“$”有时会出错;name属性值“$”可加可不加,一般不加。

【例1】value属性值使用系统变量。

为了方便测试,在配置项文件中随便添加一项配置项。

(thinkphp6开发手册)(thinkphp5.1开发手册)

①在config/app.php文件中,添加一个配置项:

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在in.html模板中,使用in标签判断,并且value属性值使用系统变量

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

2. between和notbetween

可以使用between标签来判断变量是否在某个区间范围内。

(thinkphp6开发手册)(thinkphp5.1开发手册)

1)基本用法

①在Index控制器中,新建bettag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②新建between.html模板,并使用between与notbetween标签进行判断

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

2)between与notbetween标签合并使用效果

between标签与notbetween标签合并,即成为between...else效果。

在between.html模板中将between与notbetween标签合并使用:

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

3)name属性使用系统变量

①在配置项文件(config/app.php)中,添加一个配置项

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在between.html模板中,使用between标签,name属性值使用系统变量

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

4)value属性区间范围,只支持两个值

当使用between标签的时候,value只需要一个区间范围,也就是只支持两个值,后面的值无效。

在between.html模板中设置value属性多个值:

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

5)value属性支持字母字符串判断

①在Index控制器中,修改bettag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在between.html模板中,使用between标签进行区间范围判断

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

6)value属性支持字符串、数组、系统变量

①在配置项文件(config/app.php)中,添加配置项

(thinkphp6开发手册)(thinkphp5.1开发手册)

②在between.html模板中使用between标签

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

3. present与notpresent标签

present标签用于判断某个变量是否已经定义。

(thinkphp6开发手册)(thinkphp5.1开发手册)

1)基本用法

①在Index控制器中,新建pretag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②新建present.html模板,并使用present标签和notpresent标签

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

注意:

1. 手册中说明name属性支持系统变量,但经测试,使用系统变量会报错,测试版本号为:ThinkPHP5.1.5。

【例1】测试name属性使用系统变量。

在present.html模板中,使用present标签,name属性使用系统变量。

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

4. empty与notempty标签

empty标签用于判断某个变量是否为空。

(thinkphp6开发手册)(thinkphp5.1开发手册)

1)基本用法

①在Index控制器中,新建emptytag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②新建empty.html模板,并使用empty标签与notempty标签

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

2)name属性使用系统变量

在empty.html模板中使用empty标签,name属性使用系统变量:

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

注意:

1. 判断为空的有“”、0、NULL、false以及定义变量未被赋值的。

5. defined与notdefined标签

defined标签用于判断某个常量是否有定义。

(thinkphp6开发手册)(thinkphp5.1开发手册)

①在Index控制器中,新建definedtag方法

(thinkphp6开发手册)(thinkphp5.1开发手册)

②新建defined.html模板,并使用defined与notdefined标签

(thinkphp6开发手册)(thinkphp5.1开发手册)

预览:

(thinkphp6开发手册)(thinkphp5.1开发手册)

注意:

1. defined标签name属性的值要注意严格大小写。

ThinkPHP5连载为卓象程序员原创,转载请联系卓象程序员

(thinkphp6开发手册)(thinkphp5.1开发手册)

关注卓象程序员,定期发布技术文章

下一篇讲解“模板-内置标签之资源文件加载”

(thinkphp6开发手册)(thinkphp5.1开发手册)
(thinkphp6开发手册)(thinkphp5.1开发手册)

声明:我要去上班所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,版权归原作者程序员小娇所有,原文出处。若您的权利被侵害,请联系删除。

本文标题:(thinkphp6开发手册)(thinkphp5.1开发手册)
本文链接:https://www.51qsb.cn/article/m85zk.html

(0)
打赏微信扫一扫微信扫一扫QQ扫一扫QQ扫一扫
上一篇2023-05-26
下一篇2023-05-26

你可能还想知道

发表回复

登录后才能评论