TP5 __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',  
],  

加载资源格式:

<linkhreflinkhref="__CSS__/style.css"rel="stylesheet">  
<script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="__JS__/style.js"></script>  
<img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="__IMG__/user_logo.jpg" /> 

【转自慕课】https://www.imooc.com

PHP

PHP编译安装时常见错误解决办法

2022-3-3 16:39:13

PHP

〇〇七章 日期控件与日期函数

2022-3-3 16:41:29

搜索