PHPStorm和模块参考 [英] PHPStorm and module references

查看:83
本文介绍了PHPStorm和模块参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following files at my PHP project:

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

index.php通过以下方式引用module1.php:

require_once('private/module1.php');

module1.php依次需要module2.php,因此它具有以下行:

By its turn, module1.php requires module2.php, so it has the following line:

require_once('private/module2.php');

我需要告知从根目录开始的相对路径,以便它起作用.我猜这是因为 require_once 命令期望来自 current 文档的路径,恰好是index.php.问题是PHP Storm无法管理此引用.例如,它不会将字符串private/module2.php变成超链接,也不会将其识别为实际引用.

I need to inform the relative path from root for it to work. I guess that's because require_once command expects a path from the current document, which happens to be index.php. The problem is that PHP Storm can't manage this reference. For instance, it doesn't turn the string private/module2.php into an hyperlink, nor spot it as an actual reference.

如何解决这个问题?

推荐答案

您只需要通过指定PhpStorm用于解析引用的包含路径来正确配置PhpStorm项目.

You just need to configure your PhpStorm project correctly by specifying the include paths PhpStorm should use to resolve references.

转到文件->设置-> PHP.

Go to File -> Settings -> PHP.

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

There you should add the project root directory (the one where your index.php resides) to the list of include paths.

完成此操作后,PhpStorm应该在require_once('private/module2.php')中解析路径.

When this is done PhpStorm should resolve the path in require_once('private/module2.php').

此外,您还可以通过 set_include_path()将 private 目录添加到PHP使用的包含路径列表中在您 index.php 中的某个位置.然后,您可以从 module1.php 调用require_once('module2.php').

Additionally you could add the private directory to the list of include paths PHP uses via set_include_path() somewhere in you index.php. Then you could just call require_once('module2.php') from your module1.php.

同样,您必须将 private 目录添加到PhpStorm用于使其能够解析此引用的包含路径列表中.

Again, you would have to add the private directory to the list of include paths PhpStorm uses to enable it resolve this reference.

这篇关于PHPStorm和模块参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆