`

TP5 模板

阅读更多

app\index\controller\Index.php

<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        $data['name'] = 'Chaoyi';
        $data['email'] = 'onestopweb@qq.com';
        $this -> assign('data',$data);

        $this -> assign('create_time',time());
        
        $user['name'] = '吴者然';
        $user['score'] = 50;
        $user['level'] = 10;
        $this -> assign('user',$user);
        
        $info['status'] = '1';
        $info['msg'] = '正常';
        $info['error'] = '错误';
        $this -> assign('info',$info);
        
        for($i=0;$i<10;$i++){
            $list[$i]['id'] = $i;
            $list[$i]['name'] = "chaoyi$i";
        }
        $this -> assign('list',$list);
        
        
        return $this->fetch();
    }
}

 

app\index\view\index\index.html

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title></title>
</head>
<body>

<!-- 变量输出  -->
<ol>
	<li>Name:{$data.name} Email:{$data.email}</li>
	<li>Name:{$data['name']} Email:{$data['email']}</li>
</ol>

<!-- 使用函数 -->
<pre>
{$data.name|md5} == <?php echo (md5($data['name'])); ?> <br>
{$create_time|date="Y-m-d",###} == <?php echo (date("Y-m-d",$create_time)); ?>  <br>
{$data.name|substr=0,3} == <?php echo (substr($data['name'],0,3)); ?> == {$data.name|substr=###,0,3} <br>
{$data['email']|md5|strtoupper|substr=0,3} == <?php echo (substr(strtoupper(md5($data['email'])),0,3)); ?> == {:substr(strtoupper(md5($data['email'])),0,3)}
</pre>

<!-- 使用默认值 -->
{$user.name|default="这家伙很懒,什么也没留下"}

<!-- 使用运算符 -->
<pre>
{$user.score+10}<br>
{$user['score']+10}<br>
{$user['score']*$user['level']}
</pre>

<!-- 三元运算 -->
<pre>
{$info['status']? '正常' : '错误'}<br>
{$info['status']? $info['msg'] : $info['error']}<br>
{$info.status? $info.msg : $info.error }<br>
{$varname.aa ?? '不存在'}
</pre>

<!-- 原样输出 -->
{literal}
    Hello,{$user.name}!
{/literal}

<!-- 注释  -->
{// 单行注释 }
{/* 多行
注释 */ }

<!-- 循环输出标签  -->
<p>
{volist name="list" id="vo"}
{$vo.id}:{$vo.name} 
{/volist}
<p>
<p>
{foreach $list as $vo} 
{$vo.id}:{$vo.name} 
{/foreach}
</p>

<!-- 比较标签 -->
<p>{eq name="info.status" value="1"}{$info['msg']}{/eq}</p>

<!-- 条件判断 -->
<p>
{switch name="user.level"}
    {case value="1"}value1{/case}
    {case value="2"}value2{/case}
    {default /}default
{/switch}
</p>
<p>
{if condition="($user.level == 1) OR ($user.level > 100) "} value1
{elseif condition="$user.level eq 2"/}value2
{else /} value3
{/if}
</p>

<!-- 资源文件加载 -->
{load href="/static/js/common.js" /}
{load href="/static/css/style.css" /}

{load href="/static/js/common.js,/static/css/style.css" /}

{js href="/static/js/common.js" /}
{css href="/static/css/style.css" /}

</body>
</html>

 

效果图:

 

 

 

 

 

 

 

 

 

  • 大小: 16.5 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics