ThinkPHP6.0的开发手册网址如下: https://www.kancloud.cn/manual/thinkphp6_0/
如果用Composer安装TP6, 默认是不支持视图的. 需要单独安装视图功能, 在TP6根目录运行以下指令
composer require topthink/think-view
安装视图功能后, 可以这样使用
控制器示例代码
<?php
//dir:/app/controller/Index.php
namespace app\controller;
use app\BaseController;
use think\facade\View;
class Index extends BaseController
{
public function test()
{
$data = 123;
View::assign('data', $data);
return View::fetch();
}
}
模板示例代码
<!--
dir:/view/index/test.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3>调用模板</h3>
<p>
{$data}
</p>
</body>
</html>
注意要在控制器 use think\facade\View;