php - multiple include from multiple directory error
<p>Here is my directory listing :</p>

<pre><code>&gt;htdocs
--&gt;MyWeb
----&gt;admin
------&gt;cms.php
----&gt;images
----&gt;controller
------&gt;post.php
------&gt;general.php
----&gt;model
------&gt;posts.php
------&gt;sessions.php
------&gt;connections.php
----&gt;index.php
</code></pre>

<p>and here are the includes for each page starting from top :</p>

<pre><code>cms.php:
    require_once('../model/sessions.php');
    require_once('../controller/post.php');
post.php:
    require_once('general.php');
    require_once('../model/posts.php');
general.php : none 
posts.php:
    require_once('sessions.php');
    require_once('connections.php');
sessions.php:
    require_once('connections.php');
connections.php : none
index.php:
    require_once('controller/post.php');
</code></pre>

<p>condition : tested everything fine with cms.php, i got access to all the function using forms provided by the controller, and the controller got the data from model.
now, the administration things are done, time to get to the index.php to show the data, i put  inside index.php, when i open it, here's what happened :</p>

<p><strong>I got errors which tell me that the "require_once()" function cannot locate the specified file. I did this with cms.php and its all right. The errors are not from index.php, but from
the file included within it (post.php).</strong></p>

<p>lets take a look again in index.php, it has included the controller, post.php using "require_once('controller/post.php') ;", but the post controller itself, includes another file, 
which is the post model "require_once('../model/posts.php')". The problem occurs when index.php view the required file of the controller using <strong>top folder perspective</strong> (MyWeb), then reads the file included
in post controller as exactly "require_once('../model/posts.php')" = up one folder of index.php, folder model, which mean :</p>

<blockquote>
  <p>htdocs>model>posts.php which is of course, didn't exist. I was really confused at the first time, then i create some cheats for this :</p>
</blockquote>

<pre><code>1. I put a variable $check = true ; before the require_once('controller/post.php') ; in index.php
2. then for each page that requires another file, i put these :
    //for example, in sessions.php
    if(isset($check)) {
        //old link which is like this : require_once('connections.php') ; has become :
        require_once('model/connections.php') ;
        //so in index.php perspective, the file can be reached
    }
    else {
        //old links, only executed when this page was not viewed from index.php
        require_once('connections.php') ;
    }
3. it works now, cms.php read the includes from old links, while index.php will read the included from new links.
</code></pre>

<p>Now, even though it works, my codes look ugly and inconsistent if in the future, i might add more files, more includes.
question : do anyone has better solution for this ? how to access working directories of the application, such in linux using : ~/controller/post.php or ~/model/posts.php. so the address will be consistent.
can't use getcwd(), i dont want to show the absolute path of my files. does anyone can give me better solution for specifying directories such in my case ?</p>

<p>note : pardon my english</p>
