Search code examples
phpidecommentsinclude-pathphpstorm

Helping IDE resolve file paths in included files


I have a standard front controller / bootstrap configuration, with the front controller at root/index.php and the bootstrap at root/app/bootstrap.php.

The front controller loads the boostrap file with require_once 'app/bootstrap.php';.

The bootstrap then loads necessary files using paths relative to the front controller, such as require_once 'model/model.php';.

My IDE (PhpStorm 3.0.2) flags the file paths in the bootstrap with a warning that says "Can't resolve target of expression..."

Is there a comment and/or code that can I add to the bootstrap file to help my IDE recognize and resolve the directory/inclusion scheme?


Solution

  • The following ought to work. Annoyingly, it doesn't work if you use $config->directoryroot, but there's a bug open about that here so it should work itself out in future builds.

    $directoryroot = '/full/system/path/to/docroot';
    
    require_once($directoryroot.'/app/bootstrap.php');