-
Modify the template engine
config/view.php
// 模板引擎类型使用Think
'type' => 'php',
2. Create a new controller
The name of the app in this article is test, and a new controller User is created under it
app/test/controller/User.php
Note: A reference is required think\facade\View
to manipulate the view
<?php
namespace 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');
}
}
Using assign
methods for global template variable assignment
return View::fetch('User/index');
Indicates calling the index template under the User controller.
3. Create a new page
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. Browser access
Access address http://localhost/clubs/public/index.php/test/user/index
5. If there is an external style file, put it in the public/static folder
Reference it in the following way in html
6. Operators and Labels
Operators, loop labels, if labels, comparison labels, conditional labels, etc.
Please see: https://blog.csdn.net/qzmlyshao/article/details/131013777
7. Official Tutorial
Please see https://www.kancloud.cn/manual/thinkphp6_0/1037608