Tell PhpStorm to start looking for files in a specific path

122 Views Asked by At

My Project structure looks something like this:

enter image description here

In my index.php I include the content from abilities.php with

<?php
    if (isset($_GET['site'])) {
        switch ($_GET['site']) {
            ...
            case 'abilities':
                include("./content/abilities.php");
                break;
            ...
        }
    }
?>

In abilities.php I include my Class Ability.php via

require_once ("./model/Ability.php");

which works perfect in the browser, but PhpStorm says it cannot find the class:

enter image description here

that's most likely because it searches for a model directory with the Class Ability.php in the content directory which isn't there.

So my question is how can I tell PhpStorm to start looking for files as if my abilities.php would be in the root directory like index.php?

Like setting a alternate path for abilities.php to start looking for files or something similar.

2

There are 2 best solutions below

0
marekful On BEST ANSWER

Have you configured you project structure in PHPStorm? Find Project Settings, and you can check if one is or mark a directory as 'sources'. That would the the parent directory of those shown in the screenshot in your case.

enter image description here

The screenshot is for a Java project but you can tell IDEA the same way for PHP projects where to look for source files.

0
Difster On

If you just add files to your PHPStorm project the program will pick up on them. However, I think maybe what you're really after (maybe without realizing it) is how to use namespace in PHP. It's like a programatic directory structure that your application can read. There are tons of tutorials on it along with the official PHP documentation.