亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

How does ThinkPHP 3.2 read resource files under Public?
我想大聲告訴你
我想大聲告訴你 2017-05-16 13:09:39
0
7
823

Directory structure:

project
|---App
|---Public
    |---blog-frontend
        |---Home
            |---js
            |---css
            |---img
            |---xxx.md
|---ThinkPHP
|---index.php

The content of the entry file index.php is as follows:

if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// Turn on debugging mode. It is recommended to turn it on during the development stage. Comment or set it to false during the deployment stage.
define('APP_DEBUG',true);
//Define application directory
define('APP_PATH','./App/');
//Introduce ThinkPHP entry file
require './ThinkPHP/ThinkPHP.php';
// Dear ^_^ You don’t need any code later, it’s that simple

Configured in public config.php

'TMPL_PARSE_STRING' => array(
    '__STATIC__' => __ROOT__ . '/Public/blog-frontend',
),

And use resources using Public in the view: introduce static resources

<script src="__STATIC__/Home/js/jquery.min.js"></script>

There is no problem with the above code and it was introduced successfully.

However, in the controller

function Xaction(){
    $file = "/Public/blog-frontend/Home/xxx.md";
    $fopen = fopen($file,'r');
    var_dump($fopen);
}

Output

false

Strange, I tried fopen in the view again

$file = "__STATIC__/Home/xxx.md";
$fopen = fopen($file,'r');
var_dump($fopen);

Output

false

I tried again fopen and replaced it with file_get_contents. The result was still false whether it was the output in the controller or the view. So I changed the suffix .md to .txt and the result was still false.

How to solve it?
Supplement:
Thank you for your help. Through @jiny's method, the problem has been solved.

For some reason, I print it in IndexController.class.php

var_dump(__ROOT__);
var_dump(__PUBLIC__); 

(The above is the default, I have not configured it.)

output:

string(0) ""
string(10) "__PUBLIC__" // if var_dump(__ABCDE__);// string(9) "__ABCDE__"
我想大聲告訴你
我想大聲告訴你

reply all(7)
曾經(jīng)蠟筆沒有小新
function Xaction(){
    $file = $_SERVER['DOCUMENT_ROOT']."/Public/blog-frontend/Home/xxx.md";
    $fopen = fopen($file,'r');
    var_dump($fopen);
}
//在控制器里要這么寫 $_SERVER['DOCUMENT_ROOT'] 
習(xí)慣沉默
  1. First you need to understand the directory where PHP 執(zhí)行 Xaction 這個(gè)方法的時(shí)候?qū)?yīng)的路徑是什么?
    ThinkPHP 中的入口文件擔(dān)當(dāng)著入口的作用,意味著方法的執(zhí)行實(shí)際上都是在這一文件中去完成的(各種 require),所以執(zhí)行 Xaction 的方法所在路徑即為 index.php is located

  2. It is recommended to use relative paths
    Now that you know the path of the current script, it is very clear to obtain the resource files under Public

    $file = './Public/blog-frontend/Home/xxx.md'
Ty80
我一般用$file = __ROOT__."/Public/Home/xxx.md";
迷茫

Default __PUBLIC__ You can print it and see.
I don’t think the way you tested is correct. Don’t rush to use multiple ways to prove your idea. Organize a method and go step by step.

某草草

When using fopen, check whether the directory file is configured with corresponding permissions. This may be the reason.

漂亮男人

Thanks for the invitation! Use TP的系統(tǒng)常量__PUBLIC__Quote

Peter_Zhu

Thanks for the invitation, tp provides the system constant _PUBLIC_, which can be directly referenced by defining the path under config

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template