Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It could be a good idea define absolute path. Because:</p> <ul> <li>Files/Folders could change location in the future</li> <li>Prevent issues like your question (the parent file could not be the same for different call)</li> <li>If you look the code, you know where you should find the files</li> </ul> <p>So, simply include a constant file where you can generate cascade of path like so:</p> <pre><code>define('PATH_ROOT' ,__DIR__.'/'); define('PATH_CLASSES' , PATH_ROOT.'classes/'); // ... </code></pre> <p>and in your scripts</p> <pre><code>require_once PATH_CLASSES.'controller/Class.CIAjaxHandler.php'; </code></pre> <p>In this case you are absolute sure what you include, and WHERE is the file that you want include.</p> <p>Suppose you've this structure:</p> <p><strong>/root.php</strong></p> <pre><code>&lt;?php echo "Hello World"; </code></pre> <p><strong>/index.php</strong></p> <pre><code> &lt;?php include 'path1/path1.php'; </code></pre> <p><strong>/path1/path1.php</strong></p> <pre><code>&lt;?php include '../root.php'; </code></pre> <p>In this case if you call <code>/path1/path1.php</code> the script works, because include root.php in parent folder and it's ok. But if you call <code>/index.php</code> it does not works, because the inclusion file is already relative to parent folder.</p> <p>So, if in your software you plan to call different files in different locations, use constants COULD be one solution.</p> <p>Another solution could be set an <a href="http://www.php.net/manual/en/ini.core.php#ini.include-path" rel="nofollow">include path</a> or to specify always an absolute path with <code>__DIR__</code> at start of relative path.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload