PHPStorm and module links

I have the following files in my PHP project:

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

index.php referenced by module1.php as follows:

 require_once('private/module1.php'); 

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

 require_once('private/module2.php'); 

I need to tell the relative path from the root for it to work. I assume that since the require_once command expects the path from the current document, which is index.php. The problem is that PHP Storm cannot handle this link. For example, it does not turn the private/module2.php into a hyperlink and does not indicate it as an actual link.

How to solve this?

+4
source share
3 answers

You just need to set up your PhpStorm project correctly by specifying the include paths that PhpStorm should use to resolve the links.

Go to File → Settings → PHP.

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

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

Alternatively, you can add the private directory to the list of included paths. PHP uses through set_include_path () somewhere in you index.php . Then you can just call require_once('module2.php') from your module1.php .

Again, you will need to add the private directory to the list of included paths used by PhpStorm to allow this link.

+4
source

You can also use the base url. how

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

The base url can be defined somewhere on its own or you can use the $ _SERVER variable to get it http://www.php.net/manual/en/reserved.variables.server.php

+1
source

PhpStorm cannot make a link because it is looking for

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

module1.php should just need the file name module2.php :

require_once('module2.php);

0
source

All Articles