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' => '[email protected]', '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>
效果图:
扫描二维码关注公众号,回复:
267556 查看本文章