问题
I have the following files at my PHP project:
index.php
private/module1.php
private/module2.php
The index.php
references module1.php
this way:
require_once('private/module1.php');
By its turn, module1.php
requires module2.php
, so it has the following line:
require_once('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.
How to solve this?
回答1:
You just need to configure your PhpStorm project correctly by specifying the include paths PhpStorm should use to resolve references.
Go to File -> Settings -> PHP.
There you should add the project root directory (the one where your index.php resides) to the list of include paths.
When this is done PhpStorm should resolve the path in require_once('private/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.
Again, you would have to add the private directory to the list of include paths PhpStorm uses to enable it resolve this reference.
回答2:
You could also just use the base url. Like
require_once($base_url . 'private/module2.php');
The base url can be defined somewhere by yourself or you could use the $_SERVER variable to get it http://www.php.net/manual/en/reserved.variables.server.php
回答3:
PhpStorm can't make the reference because it's looking for
index.php
private/module1.php
private/private/module2.php
module1.php
should just require the filename module2.php
:
require_once('module2.php);
来源:https://stackoverflow.com/questions/14175485/phpstorm-and-module-references