content management - global variables
<p>This is how I manage content on my site:</p>

<p><strong>PageLoader.class</strong></p>

<pre><code>class PageLoader {

        private $page_dir;
        private $page_headers = '';
        private $page_html = '';

        public function __construct($page_dir)
        {
            $this-&gt;page_dir = $page_dir;
        }

        public function load()
        {
            $file_found = false;

            ob_start();
            $file_found = include("./{$this-&gt;page_dir}");
            $file_contents = ob_get_contents();
            ob_end_clean();

            if($file_found != false)
            {
                $this-&gt;page_html = $file_contents;
            }
        }

        public function outputBody()
        {
            echo $this-&gt;page_html;
        }
    }
</code></pre>

<p><strong>index.php</strong>
    

<pre><code>$connection = mysql_connect(....);
$is_user_logged = login(...);


$view = new PageLoader($_GET['page']);
$view-&gt;load();

?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;? $view-&gt;outputHeaders(); ?&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;? $view-&gt;outputBody(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<hr>

<p>One problem with this:</p>

<p>Those two variables $connection and $is_user_logged_in are not accessible from within load() method. Most of my inner pages depend on those variables for various reasons. Since they both appear NULL in that scope, inner pages fail to function.</p>

<p>This could solve the problem: $view->setVariable("connection", $connection) but I have a lot more than 2 'main' variables so I'm not sure if this is the best way...</p>

<p>What can I do? Feel free to suggest any alternative ways for me to manage my content as my way is probably the least professional...</p>
