separate front and rear ends thinkphp

separate front and rear ends thinkphp

Simply record what course of study tp before it.

Front-end HTML page rendering

<?php
namespace app\index\controller;
use think\Controller;

class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
}

In this case, you will need to file into your front-end application / index / view, view the default folder is no need to built your own, such as: application / index / view / index.html

Front-end js / css files rendering

Generally js / css files are placed in the public / static, for example, I am here to create a new admin folder (ie / public / static / admin) then it is time to call in just rendered html, you can here Alternatively use
https://www.kancloud.cn/manual/thinkphp5/118120
then follows a new config.php i.e. the app / index under the same directory index controller

<?php
return [
    'view_replace_str'  =>  [
        '__PUBLIC__'=>'/public/static/admin/',
    ],
];

Then you enter __PUBIC__ in front of the html file which will automatically help you replace / public / static / admin /
Of course, if you just __PUBLIC__ words, the output is / public / static / admin / Then call css / when the js file is probably http: // localhost: 8888 / index.php s = / public / static / admin / this is certainly no way to call the css / js files?. Scheme can be solved as follows;
adding a constant in which /public/index.php

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]

// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
define('SITE_URL','http://127.0.0.1:8888/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';

And then just write config file

<?php
return [
    'view_replace_str'  =>  [
        '__PUBLIC__'=>SITE_URL.'/public/static/admin/',
    ],
];

In this case, the value PUBLIC__ __ http://127.0.0.1:8888//public/static/admin/ is
then in the front file which can modify the normal;
e.g.

<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">

Guess you like

Origin www.cnblogs.com/nul1/p/12239478.html