我刚开始使用PHPStorm,遇到了一个问题。
如果在包含一个文件时,然后再包含其中的另一个文件,路径将不会被正确理解。
例如: 文件夹结构:
root/ Contains index.php
view/ Contains view.php
lib/ Contains functions.php
如果我在index.php中包含view.php:
index.php:
include('view/view.php');
or
require('view/view.php');
当运行此代码时,view.php中的任何内容都将包含在index.php中,因此在view.php中包含的任何文件相对于根目录。
view.php:
include('lib/functions.php');
但是 PHPStorm 认为它们相对于视图目录。
view.php:
include('../lib/functions.php');
在这种情况下,它们并不是如此。
这个问题也发生在类似以下的情况下:
<a href="index.php">链接</a>
我该如何配置PHPStorm来解决这个问题?我原本以为它会自动解决,但目前它没有有效地解决。具体示例:
private/
privatefile.php
public/
index.php
views/view1.php //Included in index.php
views/view2.php //Included in index.php
如果我想在view1.php中包含privatefile.php,那么在这种情况下,'public'是否是资源根目录?因此,在view1.php中的include应该如下所示:include(
'../private/privatefile.php'
);
$this->classesDir = realpath(__DIR__.'/..'); require_once $this->classesDir . '/Package/Class.php';
在运行时它能够正常工作,但是PHPStorm一直显示“路径未找到”的警告。除了在每个require_once
语句前加上/** @noinspection PhpIncludeInspection */
之外,还有什么方法可以抑制这个警告吗? - pilat