thinkphp6 入门(2)--视图、渲染html页面、赋值

  1. 修改模板引擎

    config/view.php

    // 模板引擎类型使用Think    'type' => 'php',

thinkphp6 入门(2)--视图、渲染html页面、赋值_第1张图片

2. 新建一个控制器

本文app的名称为test,在其下新建一个控制器User

app/test/controller/User.php

注意:需要引用think\facade\View来操作视图

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');    }}

使用assign方法进行全局模板变量赋值

return View::fetch('User/index');

表示调用User控制器下面的index模板。

thinkphp6 入门(2)--视图、渲染html页面、赋值_第2张图片

3. 新建一个页面

app/test/view/User/index.html

​​​​​​​

        用户详情    

用户详情

我是

thinkphp6 入门(2)--视图、渲染html页面、赋值_第3张图片

4. 浏览器访问

访问地址 http://localhost/clubs/public/index.php/test/user/index

thinkphp6 入门(2)--视图、渲染html页面、赋值_第4张图片

5. 若有外部样式文件,则放到public/static文件夹

在html中通过下列的方式进行引用

thinkphp6 入门(2)--视图、渲染html页面、赋值_第5张图片

6. 运算符和标签

运算符、循环标签、if标签、比较标签、条件标签等

请看:https://blog.csdn.net/qzmlyshao/article/details/131013777

7. 官方教程

请看https://www.kancloud.cn/manual/thinkphp6_0/1037608

你可能感兴趣的:(PHP,thinkphp)