修改模板引擎
config/view.php
// 模板引擎类型使用Think 'type' => 'php',

2. 新建一个控制器
本文app的名称为test,在其下新建一个控制器User
app/test/controller/User.php
注意:需要引用think\facade\View
来操作视图
<?phpnamespace app\test\controller;
use app\BaseController;// 添加引用use think\facade\View;
class User extends BaseController{ // 渲染页面 public function index(){ // 变量赋值 View::assign('name', '张三'); // 模板输出 return View::fetch('User/index'); }}
使用assign
方法进行全局模板变量赋值
return View::fetch('User/index');
表示调用User控制器下面的index模板。

3. 新建一个页面
app/test/view/User/index.html
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>用户详情</title></head><body> <h1>用户详情</h1> <p>我是<?php echo $name ?></p></body></html>

4. 浏览器访问
访问地址 http://localhost/clubs/public/index.php/test/user/index

5. 若有外部样式文件,则放到public/static文件夹
在html中通过下列的方式进行引用

6. 运算符和标签
运算符、循环标签、if标签、比较标签、条件标签等
请看:https://blog.csdn.net/qzmlyshao/article/details/131013777