ThinkPHP6 project basic operation (11. The actual part of the deployment of the background static page template and background login page)


Preface

The backend of the website is generally developed on the basic static page, and the static page is inserted into the dynamic data. First, we first find a backend website template. Here I use it layuiAdmin 后台管理模板. Click to enter the official website . This framework is charged. Please purchase genuine commercials.

1. Deploy static resources to the project

1. Create a new background static resource folder

In the public/staticdirectory new adminfolder, layuiAdminthe distcopied files in the directory come:
Insert picture description here
go to home early adopters:http://tp6.com/static/admin/views/index.html
Insert picture description here

Two, background login page

1. Directory structure

Insert picture description here
Login controller:

<?php

namespace app\admin\controller;
use app\BaseController;
use think\facade\View;

class Login extends BaseController
{
    
    
    public function index(){
    
    
        return View::fetch('index');
    }
}

2. Template string replacement configuration

Modify the configfiles under the view.phpfolder and add string replacement configuration:

'tpl_replace_string' => [
    '{__STATIC__}' => '/static/'
],

The above configuration means that 模板引擎it will be {__STATIC__}replaced in the middle. /static/The function of using template string replacement is mainly for the convenience of maintenance. It is convenient to configure the path of all static files at one time, ../instead of worrying about how many to write . Copy the content of login.html to the template login page:

The original login page references the static file path:

<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
<link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">

change into:

<link rel="stylesheet" href="{__STATIC__}/admin/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="{__STATIC__}/admin/layuiadmin/style/admin.css" media="all">
<link rel="stylesheet" href="{__STATIC__}/admin/layuiadmin/style/login.css" media="all">

If a template 报驱动错误Driver [Think] not supported.is used for access , the reason is that tp6only PHPnative templates are supported by default , but the configuration file config/view.phpconfiguration uses it Think.
Solution:

  1. Use tp template for think-view installation
    composer require topthink/think-view
  2. Use native template
    to a profile config/view.phpin the 'type' => 'Think'revised to'type' => 'php'
  3. Use native templates
    return View::engine('php')->fetch(“index”);

Login page access:http://tp6.com/admin/login/index
Insert picture description here

Guess you like

Origin blog.csdn.net/zy1281539626/article/details/110500158