Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the <code>file_exists</code> to avoid fatal errors</p> <pre><code>// neutrals $neutrals = array('functions'); foreach ($neutrals as $neutral) { if (file_exists("../system/neutrals/{$neutral}.php") { require_once "../system/neutrals/{$neutral}.php"; } else { // Do some logging here so as to know that something went wrong } } </code></pre> <p>As for the path issues you are referring to, you can include this file from anywhere so long as you supply the proper base path for your operations. Defining a <code>ROOT_PATH</code> in your <code>index.php</code> file would help you detect where your script is and what it needs to load.</p> <p>So for instance if you have this structure:</p> <pre><code>/system /system/neutrals /system/models /public /public/index.php </code></pre> <p>in your <code>index.php</code> you can define a <code>ROOT_PATH</code> constant that will be used throughout the application and serve as a point of reference.</p> <pre><code>// this points to the folder that has /public and /system define('ROOT_PATH', dirname(dirname(__FILE__)))); </code></pre> <p>You can also have a constant just for your system folder</p> <pre><code>define('SYSTEM_PATH', ROOT_PATH . '/system'); </code></pre> <p>and then all your <code>require_once</code> declarations become:</p> <pre><code>require_once SYSTEM_PATH ."/neutrals/{$neutral}.php"; </code></pre> <p><strong>EDIT</strong>: Based on additional information in the question</p> <pre><code>Structure: /all_includes.php /system /system/neutrals /system/models /public /public/index.php /public/sub/index_sub.php </code></pre> <p>In index.php you define</p> <pre><code>// this points to the folder that has /public and /system define('ROOT_PATH', dirname(dirname(__FILE__)))); </code></pre> <p>and then:</p> <pre><code>require_once ROOT_PATH . '/all_includes.php'; </code></pre> <p>to do your initialization. The same thing happens in the <code>public/sub/index_sub.php</code>.</p> <p>Your <code>all_includes.php</code> becomes:</p> <pre><code>// neutrals $neutrals = array('functions'); foreach ($neutrals as $neutral) { if (file_exists(ROOT_PATH . "/system/neutrals/{$neutral}.php") { require_once ROOT_PATH . "/system/neutrals/{$neutral}.php"; } else { // Do some logging here so as to know that something went wrong } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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