DenHepLei Posted November 29, 2007 Share Posted November 29, 2007 Hi, I was following along in the tutorial "Introduction to PHP templating" http://phpro.org/tutorials/Introduction-to-PHP-templating.html and some have questions. Everything works as it should in the example as long as the files to be included are located in the directory root, however I would like to keep my include files in a subdirectory called "includes" and need to know how the example needs to be modified to accomplish this? I posted earlier in this forum with a simular questions but may not have been clear in what I am trying to accomplish, I apologize for the semi-duplicate post. Thanks for the assistance. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 29, 2007 Share Posted November 29, 2007 From include_once("main.php"); To $folder = "includes/"; include_once($folder."main.php"); Just add the folder onto the front of the file name and use the url to get what page to access, etc... I just used main.php as an example since they did use that. Quote Link to comment Share on other sites More sharing options...
DenHepLei Posted November 29, 2007 Author Share Posted November 29, 2007 Hi, Humm.. I must be doing something wrong, it's still not working? I have made some changes to the example, I am using the extension .inc rather than .php for the files containing the content I want displayed and I have also changed the default page from main.php to index.php, here is the code I am tyring to get working, I have a simple menu and what I want to see happen is that when you click a letter such as "A" for example the content from the file includes/a.inc is displayed, when letter "M" is clicked the content from includes/m.inc is displayed and so on... <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=a>A</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=c>C</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=d>D</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=e>E</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=f>F</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=g>G</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=m>M</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=n>N</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=p>P</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=s>S</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=t>T</a>"; echo " :: " ?> <?php echo "<a href=". $_SERVER['PHP_SELF']."?page=y>Y</a>"; ?> <!-- Begin Dynamic Content --> <?php // create an array of allowed pages $allowedPages = array('a', 'c', 'd', 'e', 'f', 'g', 'm', 'n', 'p', 's', 't', 'y'); // check if the page variable is set and check if it is the array of allowed pages if(isset($_GET['page']) && in_array($_GET['page'], $allowedPages)) { // first check that the file exists if(file_exists($_GET['page'].'.inc')) { // If all is well, we include the file include_once($_GET['page'].'.inc'); } else { // A little error message if the file does not exist echo 'No such file exists'; } } // if somebody typed in an incorrect url else { // if things are not as they should be, we included the default page if(file_exists('index.inc')) { // include the default page $folder = 'includes/'; include_once($folder.'index.inc'); } else { // if the default page is missing, we have a problem and it needs to be fixed. echo 'index.inc is missing. Please fix me.'; } } ?> <!-- End Dynamic Content --> Thanks in advance Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 29, 2007 Share Posted November 29, 2007 Didn't add the includes folder here (so do it): $folder = 'includes/'; // check if the page variable is set and check if it is the array of allowed pages if(isset($_GET['page']) && in_array($_GET['page'], $allowedPages)) { // first check that the file exists if(file_exists($folder.$_GET['page'].'.inc')) { // If all is well, we include the file include_once($folder.$_GET['page'].'.inc'); } else { // A little error message if the file does not exist echo 'No such file exists'; } } // if somebody typed in an incorrect url else { // if things are not as they should be, we included the default page if(file_exists($folder.'index.inc')) { // include the default page include_once($folder.'index.inc'); } else { // if the default page is missing, we have a problem and it needs to be fixed. echo 'index.inc is missing. Please fix me.'; } } 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.