Since you're using a programming language, you're not really limited to using the include function in this way. This, at it's root, is the difference between just using templates, and a full-blown web application. A specific example will make things more clear.
Say you had files called header.php, navbar.php, and footer.php and they all appear on each page. The natural tendancy is to then include those files on other pages where you need them. My normal recommendation to students and trainees is to do exactly the opposite. Put all those components on ONE page, in ONE place, and then call the script you need in a VARIABLE in your include file. For example, let's say you had an ';index.php'; file, that looks something like this...
%26lt;html%26gt;
%26lt;head%26gt;
%26lt;title%26gt;%26lt;?php echo $page_title ?%26gt;%26lt;/title%26gt;
%26lt;/head%26gt;
%26lt;body%26gt;
%26lt;?php require_once('header.php') ?%26gt;
%26lt;table%26gt;
%26lt;tr%26gt;
%26lt;td%26gt;%26lt;?php require_once('navbar.php') ?%26gt;%26lt;/td%26gt;
%26lt;td%26gt;%26lt;?php require_once($_GET['page'] . '.php') ?%26gt;%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;/table%26gt;
%26lt;?php require_once('footer.php') ?%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;
Now, let's say you had a page called ';hello.php';. You could call it from your index page like this...
http://www.example.com?page=hello
And of course, with a bit of trickery using Apache's mod_rewrite module, you could easily convert that to...
http://www.example.com/helloPhp pages (root directory)?
You could try and use php's 'predefined variables'.
$link = $DOCUMENT_ROOT . ';/left_nav.inc';;
include $link;
You could edit the above to suit your needs..
No comments:
Post a Comment