Thinkphp6 Getting Started (2)--view, rendering html page, assignment

  1. Modify the template engine

    config/view.php

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

picture

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\Viewto manipulate the 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');    }}

Using assignmethods for global template variable assignment

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

Indicates calling the index template under the User controller.

picture

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>

picture

4. Browser access

Access address http://localhost/clubs/public/index.php/test/user/index

picture

5. If there is an external style file, put it in the public/static folder

Reference it in the following way in html

picture

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

Guess you like

Origin blog.csdn.net/u013288190/article/details/132548196