r00t0101 Posted April 18, 2009 Share Posted April 18, 2009 Hello all, I was wondering if this could be done. I would like to re-design my site where the files being called on is using global variables instead of using syntax "../" or "../../". I would like use a more readable approach using global variables like $dir_name/file_name instead if possible. I figured this way there will only be one place to update instead of scanning through the whole file doing a search and replace on each item. Below is a general idea of what I would like. In this example I have four files: a global, header, footer and an index file. The index file includes the global file without a problem however I had problems executing the header and footer files when using variables as seen commented. Respectively yours, Rick <!-- Start testGlobal.php --> <? $CFG->root = "http://127.0.0.1/test"; $CFG->headerDir = "$CFG->root/header"; $CFG->footerDir = "$CFG->root/footer"; ?> <!-- End testGlobal.php --> <!-- Start index.php --> <?php include("TestGlobal.php"); ?> <!-- <? echo $CFG->headerDir; ?>/header.php --> <?php include ("./header/header.php"); ?> bla bla bla<br><br> <!-- <? echo $CFG->footerDir; ?>/footer.php --> <?php include ("./footer/footer.php"); ?> <!-- End index.php> <!-- Start header.php --> <html> <head> <title>Hello world</title> </head> Header Test Section<br><br> <body> </html> <!-- End header.php --> <!-- Start footer.php --> Copyright @ test.com <!-- End footer.php> Quote Link to comment Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 The root needs to be a filesystem path rather than a web url for including. try: $CFG->root = dirname(__FILE__); Quote Link to comment Share on other sites More sharing options...
r00t0101 Posted April 20, 2009 Author Share Posted April 20, 2009 Just curious, so there is no way to use URLs in my example. Just wondering how that would work if the site is being hosted other than locally? I tried $CFG->root = /var/www as well as some other combinations but I still get errors. Quote Link to comment Share on other sites More sharing options...
AE117 Posted April 20, 2009 Share Posted April 20, 2009 Just curious, so there is no way to use URLs in my example. Just wondering how that would work if the site is being hosted other than locally? I tried $CFG->root = /var/www as well as some other combinations but I still get errors. i think you can not sure but give something like this a try <?php $CFG->root = "http://127.0.0.1/"; $header = "header"; $CFG->headerDir = $CFG->root.$header; ?> that should output (using and echo statment) http://127.0.0.1/header Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.