| controller檔案 public function index(){ View::assign('a',100); View::assign(' b',21); return View::fetch(); #}
view檔案 ##<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> 二、模版函數 方法說明#firstlast | | | | | | | | | | #date | 日期格式化(支援各種時間類型) | #format | 字串格式化 | #upper | 轉換為大寫 | #lower | #轉換成小寫 | | | 輸出陣列的第一個元素 | | 輸出陣列的最後一個元素######### ###default######預設值############raw#######不使用(預設)轉義############ md5######md5加密############substr#######截取字串############controller檔案 public function index(){ View: :assign('time',1576048640); View::assign('num',10.0032); View::assign('str','OUyangKE'); View::assign('arr',[ '朱老師', '歐陽克', ##o '歐陽克',## 大官 '西門大官人 '西門勳爵人 # ]); return View::fetch();} view檔案#< div>{$time|date='Y-m-d H:i:s'}</div><div>{$num|format=' d'}</div><div>{$str|upper}</div>#<div>{$str|lower}</div>#<div> {$arr|first}</div><div>{$arr|last}</div><div>{$default|default="歐陽克"}</div><div>{$str|substr=0,3}</div><div>{$str|md5}< ;/div><div>{$str|lower|substr=0,3}</div> 三、循環標籤controller檔案public function index(){ $arr = [ [ 'id' => 1,# 'id' => 1,# #. => '歐陽克' ], [ 'id' => 2,# 'id' => 2,# 鎠 名詞老師 ' ],## [ 'id' => 3, ## ## ] ]; View::assign('arr',$arr); return View::fetch(); } view文件{foreach $arr as $v} <div> # < span>ID:{$v['id']}</span> <span>姓名:{$v['name']}</span> </div> {/foreach}
四、volist 迴圈標籤二維陣列的結果輸出 - ##name 範本賦值的變數名稱
##id 目前的循環變量,可以隨意命名 key 下標,從1開始,預設變數i offset 開始行數 #length 取得行數 empty如果資料為空,顯示此文字 view檔案 {volist name="arr" id="v" key="k" offset= "1" length="2"} <div> <span>ID:{$v['id']}</span> # <span>姓名:{$v['name']}</span> <span>下標:{$k}</s#gt; ;/div> {/volist} 五、if 判斷標籤 if 標籤的用法和PHP語法非常接近,用於條件判斷 controller檔案
public function index(){ View::assign( 'status',1); View::assign('order_status',4); 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}六、switch 判斷標籤
switch 標籤的用法和PHP語法非常接近,用於條件判斷view檔案
{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} 七、包含檔案include 標籤,引入模版檔案
load 標籤,引入資源檔案(css、js)
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" /}
#八、其他標籤1、條件標籤 標籤 | 描述 | in | 判斷變數是否存在某些值 | #notin | 判斷變數是否不存在某些值 | #between | 判斷變數是否存在某些值 | notbetween | 判斷變數是否不存在某些範圍值 | present | 判斷某個變數是否已定義 | notpresent | 判斷某個變數是否未定義 | empty | 判斷某個變數是否為空 | notempty | 判斷某個變數是否不為空 | defined | 判斷某個常數是否已定義 | notdefined | 判斷某個常數是否未定義 | public function index(){
View::assign('number',100);
View::assign('string','');
return View::fetch();
} {in name="number" value="99,100,101"}
number等于99,100,101任意一个值
{/in}
{notin name="number" value="99,100,101"}
number不等于99,100,101任意一个值
{/notin}
{between name="number" value="1,10"}
number等于1 到 10 之间的任意一个值
{/between}
{notbetween name="number" value="1,10"}
number不等于1 到 10 之间的任意一个值
{/notbetween}
{present name="number"}
number已经定义
{/present}
{notpresent name="n"}
n还没有定义
{/notpresent}
{empty name="string"}
name为空值
{/empty}
{notempty name="string"}
name有值
{/notempty}
{defined name="NAME"}
NAME常量已经定义
{/defined}
{notdefined name="NAME"}
NAME常量未定义
{/notdefined} 2、比較標籤 #標籤 | 描述 | eq | 等於 | neq | 不等於 | gt | 大於 | egt | 大於等於 | lt | #小於 | elt | 小於等於 | heq | 恆定等於 | nheq | #不恆等於 |
public function index(){
View::assign("number",100);
View::assign("string","欧阳克");
return View::fetch();
} {eq name="number" value="100"}
number 等于 100
{/eq}
{neq name="number" value="101"}
number 不等于 101
{/neq}
{gt name="number" value="33"}
number 大于 33
{/gt}
{egt name="number" value="100"}
number 大于等于 100
{/egt}
{lt name="number" value="200"}
number 小于 200
{/lt}
{elt name="number" value="100"}
number 小于等于 100
{/elt}
{heq name="string" value="欧阳克"}
string 恒等于 欧阳克
{/heq}
{heq name="string" value="朱老师"}
string 恒不等于 朱老师
{/heq} 3、循環標籤 start:開始值 end:結束值 step:步進值,預設1 name:循環變量名,預設i
{for start="1" end="50" step="5" name="i"}
{$i}<br/>
{/for} 4、雜項標籤 ##描述literal原樣輸出php 使用原生php程式碼{literal}
{$name} 这里$name不会被当作变量,而是普通字符
{/literal}
{php}
echo '欧阳克';
{/php} 9、範例controller程式碼 namespace app\controller; use think\facade\View; #class Index { public function index(){ $title = '商城'; $login = '歐陽克'; ## $login = '歐陽克';# $ le [ 'title' => '商品管理', # [# 'id' => 1, 'title' => '商品清單',## [ 'id' = > 2, 'title' => '商品分類', ] ], [ 'title' => '使用者管理', 'list 'id' => 3 , 'title' => '使用者名單', [ 'id' => 4, 'title' => '購物車', 'id' => 5, title' => '使用者位址', ], 時中使用 'title' => '訂單管理', ] ] ], # 'lists' => ; [ [ 'title' => '管理員名單', ], [ 'title' => '個人中心', ], # [ title' => '左側選單列', ## ] 之後 ] ## ]## ]; $right = [ 1, 'title' => '熙世界2019秋冬新長袖杏桃色上衣連帽寬鬆刺繡文藝落肩袖加厚衛衣BF風', ## 'cat 套裝 袖加厚衛衣 ## 'price' => 189, 'discount' => 6, #圖片 'status' => 1, 'status' => 1, // 'status' => '69,# #) 開啟1001 開啟? 2-12', // 'add_time' => '1576080000' 'id' => 2, 'title' => '秋水伊人雙面呢冬裝2019年新款女式氣質西裝領撞色羊毛大衣外套女', ##, ', #, '#; 'price' => 699, 'discount' => 7,# ) 'statstat## # 問題 'statstatc' = # 1. status' => '開啟', 'add_time' => '2019-12-12', time) ], [ 'id' => 3, @ @@ 2gt; 3, @ @, 300,000 30,000 微男腳牛仔褲#tle' 'cat' => '男裝', 'price' => 179, status' => 0, // 'status' => '開啟', 'add_time' => '2019-1 'add_time' => // 'add_time ' => '1576080000' ], [ ## 'title' => '男士長袖t卹秋季圓領黑白體卹T 純色上衣服打底衫', '貓' => '男裝', '價格' => 99、 '折扣' => 9. '狀態' => 1, // '狀態' => '開啟', 'add_time' => '2019-12-12', // 'add_time' => '1576080000' ], ]; # 'login' => $login, 'left' => $left, # return View::fetch(); } } view程式碼:head.html# ## {$title}--後台管理系統< ;/title><blockquote> <p> <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"><br/></p> <腳本type="text/javascript" src=" /static/layui/layui.js"></script><p></p> <style type="text/css"><p></p> .header{寬度:100%;高度:50px;行高:50px;背景:#2e6da4;顏色:#ffffff;}<p></p> .title{左邊距: 20px;字體大小: 20px; }<p></p> right .useruserinfo : 10px;}<p></p> .userinfo a{color:#ffffff;}<p></p> .menu{寬度: 200px; main{位置:絕對;左:200px;右:0px;}<p></p><p></p><p> .layui-折疊{邊框:無;}</p><p> .layui-colla -item{border-top:none;}</p><p> .layui-colla-title{背景:#42485b;顏色:#ffffff; }</p><p> .layui-colla-content{b-top## .layui-colla-content{b-toptop# :none;padding:0px;}</p><p><br/></p><p> .content span{背景: #009688;margin -left: 30px;padding: 10px;}:#ffffffff;}##ffffffff; </p># .content div{border-bottom: Solid 2px #009688;margin-top: 8px;}<p><p> .content 按鈕{float: right;margin-top: -5px;}</p><p> </style></p><p>#</head></p><p>#<body> ;</p><p> <div class="header"></p><p> <span class="title"><span style="font-size: 20px;">{$ title}</span>- -後台管理系統</span></p><p> <span class="userinfo">【{$login}】<span><a href="javascript :;">退出< /a></span></span></p><p> </div></p></blockquote><p>view程式碼:left.html</p> <blockquote><p>#div class="menu" id="menu"><br/></p><p> <div class="layui-collapse" 折疊手風琴></p><p> {foreach $left as $k=>$left_v} </p><p> <div class="layui-colla-item"></p><p> <h2 class="layui-colla-title ">{$left_v.Ttle}> </p> <div class="layui-colla-content {if $k==0}layui-show{/if}"><p></p>&lt; ul class =「 layui-nav layui-nav-tree 」&gt; <p></p> class="layui-nav-item"><a href="index.html">{$lists_v.title}</a></li><p></p> {/foreach}<p></p> </div><p></p> {/foreach}<p></p> < /div><p></p></div>;</p></blockquote><p>view程式碼:bottom.html</p><blockquote><p>#</body><br/></p><p></html></p><p></p><p></p> <script><p></p> layui.use(['element','layer','laypage'], function(){<p></p> var element =layui.element;<p></p> # varlaypage =layui.laypage;<p></p> $ =layui.jquery;<p></p> 層=layui.layer;<p></p> <p>## // 重新設定選單容器高度</p><p> function resetMenuHeight(){</p><p> var height = document.documentElement .clientHeight - 50;</p> menu').height(height);<p></p> }<p></p>#</script><p></p>##view程式碼:index.html</blockquote><p></p> #{include file="public/head" /}<blockquote><p><br/>#{include file="public/left" /}</p><p><div class="main" style= "padding :10px;"></p><p> <div class="content"></p><p># <span>商品清單</span></p><p># <div> ;</div> </p>## </div>;</p><p> <table class="layui-table"></p><p> <thead></p><p> <tr<## <tr<..## ;/th></p><p> <th>商品標題</th></p><p> <th>原價< /th></p><p> <th>折扣</th></p><p> <th>庫存</th> ;</p><p> <th>狀態</th></p><p> <th< 新增時間;#/gt; </p># # </thead><p></p> <tbody><p></p> {volist name="right" #lt_v"}# # <p> <td>{$right_v.id}</td></p><p> <td>{$right_v .cat}</td></p><p> ; ;/td> </p><p> <td></p><p> # {$right_v.price*($right_v.discount/10)}</p> <p> {else/}</p><p> {/if}</p><p> </td></p><p> <td>{$right_v.stock}</td></p><p> /1] 開啟 $1}{10/L/Sstat 開啟 $ ;/td></p><p> <td>{$right_v.add_time|date='Y-m-d'}</td {/ volist}</p><p> </tbody></p><p># </table></p><p></div></p><p>{include file="公共/底部" /}</p><p></p><p></p></blockquote><p><br/></p><p><br/>##</div></div><div class="previous-next-links"><div class="previous-design-link">← <a href="/thinkphp/thinkphp-tp6-start.html" rel="prev">起步:MVC模式</a></div><div class="next-design-link"><a href="/thinkphp/thinkphp-tp6-configuration.html" rel="next">ThinkPHP6.0 配置</a> →</div></div><div class="sidebar-box ad-box ad-box-large"><div class="ad-336280"></div></div></div></div></div></div><div id="codeMark"></div><div id="codeMain"><div class="left"><div id="codeEditor"></div><div class="editor-btn"><div class="editor-btn-inner"><a href="javascript:;" class="code-btn-submit r" id="J_Commit" title="提交">提交</a></div></div></div><div class="right"><div id="codeResult"></div></div><div id="close"></div></div><script src="/static/js/CodeRunOnline.js?1.1"></script><script src="/static/src-min-noconflict/ace.js"></script><footer><a href='https://m.php.cn/zh-tw/' ><i
class='layui-icon layui-icon-home '></i>首頁</a><a href='/course.html' ><i
class='layui-icon layui-icon-play'></i>影片</a><a href="https://m.php.cn/zh-tw/wenda.html" ><i
class='layui-icon layui-icon-code-circle'></i>問答</a><a href='https://m.php.cn/zh-tw/login' ><i class='layui-icon layui-icon-username'></i>我的</a></footer><div class="right_menu"><div class="right_menu_con"><h2 class="hjclass-txt"><i class="layui-icon layui-icon-shrink-right hjclass-txt-i"></i>PHP中文網</h2><div class="menu-list"><a href="https://m.php.cn/zh-tw/"><span class="item-icon item-1"><img src="https://img.php.cn/upload/article/000/000/003/5bffb65f99ae2304.png" alt="首頁"></span>首頁</a><a href="https://m.php.cn/zh-tw/course.html"><span class="item-icon item-7"><img src="https://img.php.cn/upload/article/000/000/003/5bffb82bd09ad628.png" alt="課程"></span>課程</a><a href="https://m.php.cn/zh-tw/article.html"><span class="item-icon item-4"><img src="https://img.php.cn/upload/article/000/000/003/5bffb7e111b3b425.png" alt="文章"></i></span>文章</a><a href="https://m.php.cn/zh-tw/wenda.html"><span class="item-icon item-2"><img src="https://img.php.cn/upload/article/000/000/003/5bffb83f04e24328.png" alt="問答"></span>問答</a><a href="https://m.php.cn/zh-tw/dic.html"><span class="item-icon item-9"><img src="https://img.php.cn/upload/article/000/000/003/5bffb85047b25758.png" alt="詞典"></span>詞典</a><a href="https://m.php.cn/zh-tw/course/type/99.html"><span class="item-icon item-3"><img src="https://img.php.cn/upload/article/000/000/003/5bffb8736ea90300.png" alt="手册"></span>手册</a><a href="https://m.php.cn/zh-tw/xiazai/"><span class="item-icon item-5"><img src="/static/images/ico/resources.png" alt="下載"></span>下載</a><a href="https://m.php.cn/zh-tw/search"><span class="item-icon item-6"><img src="https://img.php.cn/upload/article/000/000/003/5bffb880b460a204.png" alt="搜尋"></span>搜尋</a><a href="https://m.php.cn/zh-tw/app/"><span class="item-icon item-6"><img src="https://img.php.cn/upload/article/000/000/003/608bbfa30d9cc398.png" style="width:35px;height:35px;" alt="APP下載"></span> APP下載</a></div></div></div><script>isLogin = 0;</script><script type="text/javascript" src="/static/js/jquery.min.js"></script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script><script>(function () {
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
} else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?43f47cabf6856204df6d083dd89ae407";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script></body></html> |