ThinkPHP5 debug: __STATIC__缺少 public 的解决方案

原有预定义资源路径__STATIC__在路径中未包含缺少public目录

使用系统变量获取当前脚本路径 $_SERVER['SCRIPT_NAME']

 

http://localhost/项目/public/index.php

dirname() 函数返回路径中的目录部分

 

dirname($_SERVER['SCRIPT_NAME']);
http://localhost/项目/public

在应用下配置文件config.php中第141行,更改如下

 

    // 视图输出字符串内容替换
    'view_replace_str'       => [
        '__PUBLIC__' => dirname($_SERVER['SCRIPT_NAME']),
        '__STATIC__' => dirname($_SERVER['SCRIPT_NAME']) . '/static',
        '__CSS__'    => dirname($_SERVER['SCRIPT_NAME']) . '/static/css',
        '__JS__'     => dirname($_SERVER['SCRIPT_NAME']) . '/static/js',
        '__IMG__'    => dirname($_SERVER['SCRIPT_NAME']) . '/static/images',
    ],

加载资源格式:

 

<linkhref="__CSS__/style.css"rel="stylesheet">
<script src="__JS__/style.js"></script>
<img src="__IMG__/user_logo.jpg" />

 

猜你喜欢

转载自blog.csdn.net/wildye/article/details/79015771