【发布时间】:2018-10-18 00:13:23
【问题描述】:
我遇到了这个问题:
在pseudoRoot/Dir/api/index.php 我有:
<php
require "SomeFolder/index.php";
?>
在pseudoRoot/Dir/api/SomeFolder/index.php 我有:
<php
require "SomeDeepFolder/someScript.php";
?>
pseudoRoot/Dir/api/SomeFolder/SomeDeepFolder/someScript.php.
现在SomeFolder 中的所有内容都是一些我不想弄乱的第 3 方库,并且需要/包含在上面的 SomeFolder/index.php 的伪中。调用pseudoRoot/Dir/api/index.php 会导致错误failed to open stream: No such file or directory。据我了解,这与 PHP 处理相对路径的奇怪方式有关(第二个 require/include 具有第一个文件的相对路径而不是他自己的)但是我怎样才能使这种路由工作而不必弄乱lib的文件意味着不接触.../SomeFolder中的任何东西并且只使用.../api/index.php?我试过使用require dirname(__FILE__) . /SomeFolder/index.php,但没有成功。
啊,“流”通过.htaccess 中的重写规则到达pseudoRoot/Dir/api/index.php,将所有请求路由到它。
对不起,如果问题重复,还没有找到任何答案。
【问题讨论】:
标签: php routing include require