PHPStorm和模块引用


PHPStorm and module references

在我的PHP项目中有以下文件:

index.php
private/module1.php
private/module2.php

index.php以这种方式引用module1.php:

require_once('private/module1.php');

反过来,module1.php需要module2.php,所以它有以下行:

require_once('private/module2.php');

我需要通知相对路径从根为它的工作。我猜这是因为require_once命令期望从当前文档的路径,这恰好是index.php。问题是PHP Storm不能管理这个引用。例如,它不会将字符串private/module2.php转换为超链接,也不会将其识别为实际引用。

如何解决这个问题?

你只需要通过指定PhpStorm应该用来解析引用的include路径来正确配置你的PhpStorm项目。

进入文件->设置-> PHP。

您应该将项目根目录(index.php所在的目录)添加到包含路径列表中。

当此操作完成后,PhpStorm将解析require_once('private/module2.php')中的路径。

此外,您可以通过set_include_path()在您的index.php中某处添加私有目录到PHP使用的包含路径列表中。然后你可以从你的module1.php调用require_once('module2.php')

同样,您必须将private目录添加到PhpStorm使用的包含路径列表中,以启用它解析此引用。

您也可以直接使用基url。像

require_once($base_url . 'private/module2.php');

基本url可以自己在某处定义,也可以使用$_SERVER变量来获取它http://www.php.net/manual/en/reserved.variables.server.php

PhpStorm无法创建引用,因为它正在寻找

index.php
private/module1.php
private/private/module2.php

module1.php应该只需要文件名module2.php:

require_once('module2.php);