ITeye博客

TP5 fetch() 渲染模板输出

onestopweb · 2017-08-06 11:49 · 境-PHPTP · Web前端 · Markdown

app\index\controller\Index.html

<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        //模板变量赋值
        $username = 'chaoyi';
        $this -> assign('username',$username);
        /**
         * 渲染模板输出
         * 第一参数:模板文件
         * 第二参数:模板变量(数组)
         * 第三参数:模板替换(数组)
         */
        return $this->fetch('index',[
            'email' => 'onestopweb@163.com',
            'dictum' => '一直专注于网站'
        ],[
            '一直' => '永远'
        ]);
    }
}

 

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>
<p>我的名字:{$username}</p>
<p>我的电子邮箱:{$email}</p>
<p>我的口号:{$dictum}</p>
</body>
</html>

 

效果图:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。