How does ThinkPHP5.1 output the URL path of the public/static static resource file in the template?

because this project may not be placed in the WEB root directory, it will be placed in a subdirectory, or the IP of the server may be modified frequently ( this project is open on both the extranet and the intranet, but the open URL of the extranet and the intranet is different, and it even makes a virtual directory, which is a bit strange ), so you can"t write it in the template

.

I have tried variables such as script_filename,script_name,pathinfo,REQUEST_URI of $_ SERVER. After using pathinfo, they will also bring the information of pathinfo into it, causing them to use dirname to get the directory where these variables are located, and what they get is not the URL of the public directory where the real index.php is located

.

and cannot be determined by judging the index.php in url, because it is possible that the server has also done URL rewriting, so the string index.php does not necessarily exist in URL and cannot be solved by string cutting.

if the current page is 192.168.1.1 static/js/ subDirindexindex.phpindexActionadminActionTest, then writing static/js/ directly in the template will be parsed to the 192.168.1.1/subDir/index.php/index/admin/test/static/js/ by the browser, so this method is not valid

is there any other way to get the URL path of the public/static static resource file?

I have tried to write _ _ STATIC__ or _ _ ROOT__, directly in the template. The results are all output as is in the direct browser


Php
Mar.18,2021

you can define some js variables globally. Just put the template variables in
clipboard.png

clipboard.png



config.php

clipboard.png

like this.

two solutions:
1. Modify the server default_server to point to the subDir directory, so there is no need to add a subDir path for ip access. Local area network and public network access methods are unified
2. Write a method to judge the access mode of local area network and public network, and return different host_name


for the two cases.

with the help of SF.GG 's official communication group, we finally found a solution.

use the following configuration in the template configuration file of ThinkPHP

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

then use the _ _ STATIC__ constant directly in the template to perfectly fit various protocols, seed paths, and cases with pathinfo

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea8d11-47cdc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea8d11-47cdc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?