标签类型 | 描述 |
---|---|
普通标签 | 主要用于输出变量、函数过滤和做一些基本的运算操作 |
XML标签 | 也称为标签库标签,主要完成一些逻辑判断、控制和循环输出,并且可扩展 |
controller文件
- public function index(){
- View::assign('a',100);
- View::assign('b',21);
- return View::fetch();
- }
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
-
- namespace app\controller;
-
- use app\BaseController;
- use think\facade\View; // 使用模板引擎
-
- class Index extends BaseController
- {
- public function index()
- {
-
- View::assign('a',100);
- View::assign('b',21);
-
- View::assign('time',1576048640);
- View::assign('num',10.0032);
- View::assign('str','OUyangKE');
- View::assign('arr',[
- '雪碧',
- '可口可乐',
- '红酒 '
- ]);
-
-
-
- // 按照默认的视图解析流程
- // 找到当前目录下的view视图目录
- // 规则是 控制器名(小写+下划线)/方法名.html
- return view::fetch();
- //return '';
- }
-
- public function hello($name = 'ThinkPHP8')
- {
- return 'hello,' . $name;
- }
-
- public function home(){
- return view::fetch();
- }
-
- }
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
- <div>{$time|date='Y-m-d H:i:s'}div>
- <div>{$num|format='%02d'}div>
- <div>{$str|upper}div>
- <div>{$str|lower}div>
- <div>{$arr|first}div>
- <div>{$arr|last}div>
- <div>{$default|default="cafe"}div>
- <div>{$str|substr=0,3}div>
- <div>{$str|md5}div>
- <div>{$str|lower|substr=0,3}div>
-
- namespace app\controller;
-
- use app\BaseController;
- use think\facade\View; // 使用模板引擎
-
- class Index extends BaseController
- {
- public function index()
- {
-
- View::assign('a',100);
- View::assign('b',21);
-
- View::assign('time',1576048640);
- View::assign('num',10.0032);
- View::assign('str','OUyangKE');
-
- $arr = [
- [
- 'id' => 1,
- 'name' => '可口可乐'
- ],
- [
- 'id' => 2,
- 'name' => '叶大牛'
- ],
- [
- 'id' => 3,
- 'name' => '官人快来'
- ]
- ];
- View::assign('arr',$arr);
-
-
-
-
- // 按照默认的视图解析流程
- // 找到当前目录下的view视图目录
- // 规则是 控制器名(小写+下划线)/方法名.html
- return view::fetch();
- //return '';
- }
-
- public function hello($name = 'ThinkPHP8')
- {
- return 'hello,' . $name;
- }
-
- public function home(){
- return view::fetch();
- }
-
- }
-
- {foreach $arr as $v}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- div>
- {/foreach}
-
-
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
-
view文件
-
- {volist name="arr" id="v" key="k" offset="1" length="2"}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- <span>下标:{$k}span>
- div>
- {/volist}
-
- {foreach $arr as $v}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- div>
- {/foreach}
-
-
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
-
-
-
controller文件
-
- namespace app\controller;
-
- use app\BaseController;
- use think\facade\View; // 使用模板引擎
-
- class Index extends BaseController
- {
- public function index()
- {
-
-
-
- View::assign('status',1);
- View::assign('order_status',4);
-
-
-
- View::assign('a',100);
- View::assign('b',21);
-
- View::assign('time',1576048640);
- View::assign('num',10.0032);
- View::assign('str','OUyangKE');
-
- $arr = [
- [
- 'id' => 1,
- 'name' => '可口可乐'
- ],
- [
- 'id' => 2,
- 'name' => '叶大牛'
- ],
- [
- 'id' => 3,
- 'name' => '官人快来'
- ]
- ];
- View::assign('arr',$arr);
-
-
-
-
- // 按照默认的视图解析流程
- // 找到当前目录下的view视图目录
- // 规则是 控制器名(小写+下划线)/方法名.html
- return view::fetch();
- //return '';
- }
-
- public function hello($name = 'ThinkPHP8')
- {
- return 'hello,' . $name;
- }
-
- public function home(){
- return view::fetch();
- }
-
- }
view文件
-
-
- {if $status == 1}
- <div>开启div>
- {/if}
-
- {if $status == 0}
- <div>关闭div>
- {else/}
- <div>开启div>
- {/if}
-
- {if $order_status == 0}
- <div>未支付div>
- {elseif $order_status == 1/}
- <div>已支付 待发货div>
- {elseif $order_status == 2/}
- <div>已发货 待收货div>
- {elseif $order_status == 3/}
- <div>已收货 待评论div>
- {elseif $order_status == 4/}
- <div>已完成div>
- {/if}
-
-
-
- {volist name="arr" id="v" key="k" offset="1" length="2"}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- <span>下标:{$k}span>
- div>
- {/volist}
- {foreach $arr as $v}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- div>
- {/foreach}
-
-
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
-
-
-
-
- {switch $order_status}
- {case 0 }<div>未支付div>{/case}
- {case 1 }<div>已支付 待发货div>{/case}
- {case 2 }<div>已发货 待收货div>{/case}
- {case 3 }<div>已收货 待评论div>{/case}
- {case 4 }<div>已完成div>{/case}
- {/switch}
-
-
- {if $status == 1}
- <div>开启div>
- {/if}
-
- {if $status == 0}
- <div>关闭div>
- {else/}
- <div>开启div>
- {/if}
-
- {if $order_status == 0}
- <div>未支付div>
- {elseif $order_status == 1/}
- <div>已支付 待发货div>
- {elseif $order_status == 2/}
- <div>已发货 待收货div>
- {elseif $order_status == 3/}
- <div>已收货 待评论div>
- {elseif $order_status == 4/}
- <div>已完成div>
- {/if}
-
-
-
- {volist name="arr" id="v" key="k" offset="1" length="2"}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- <span>下标:{$k}span>
- div>
- {/volist}
- {foreach $arr as $v}
- <div>
- <span>ID:{$v['id']}span>
- <span>姓名:{$v['name']}span>
- div>
- {/foreach}
-
-
- <div>{$a+$b}div>
- <div>{$a-$b}div>
- <div>{$a*$b}div>
- <div>{$a/$b}div>
- <div>{$a%$b}div>
- <div>{$a++}div>
- <div>{++$a}div>
- <div>{$a--}div>
- <div>{--$a}div>
- <div>{$c ? '存在' : '不存在'}div>
-
-
-
view文件,把头部和尾部分文件
- {include file="public/header" /}
- {include file="public/left" /}
-
- {load href="/static/layui/css/layui.css" /}
- {load href="/static/layui/layui.js" /}
-
- {include file="public/tail" /}