`

TP5 fetch() 渲染模板输出

阅读更多

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>

 

效果图:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

相关推荐

Global site tag (gtag.js) - Google Analytics