thinkphp5.1模板中获取资源文件路径

thinkphp5.1月thinkPHP5.0不同没有默认设置任何模板替换变量,如果需要使用模板替换,需要在template.php配置文件中添加如下:

'tpl_replace_string'  =>  [
        '__STATIC__'=>$_SERVER['REQUEST_SCHEME'] .'://' . $_SERVER['HTTP_HOST'] . str_replace('/index.php' ,'' ,$_SERVER['SCRIPT_NAME']) . '/static',
    ],

然后在模版中直接使用__STATIC__常量即可,完美适配各种协议,各种子路径,以及带有pathinfo的情况

猜你喜欢

转载自blog.csdn.net/qq_25987491/article/details/82713866