1internet Posted January 17, 2013 Share Posted January 17, 2013 (edited) So my site has a template, and each page plugs into it. But the pages are made dynamically, and some have directories, e.g. /directory/page, /directory2/page2, /directory2/sub-directory2/page3, etc. If I want to include my template so the include function will display the template for every page, no matter how large the directory, how should it be coded? I thought if I had include '/template.php' , then it would be the same as mydomain.com/template.php and work on every level, but this doesn't appear to be the case. Edited January 17, 2013 by 1internet Quote Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/ Share on other sites More sharing options...
kicken Posted January 17, 2013 Share Posted January 17, 2013 include $_SERVER['DOCUMENT_ROOT'].'/template.php'; When dealing with file paths in PHP, '/' refers to the file-system root, not the root of your domain. You can determine the root of your domain using the $_SERVER['DOCUMENT_ROOT'] variable. Quote Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406489 Share on other sites More sharing options...
1internet Posted January 17, 2013 Author Share Posted January 17, 2013 (edited) Right, I was thinking it would be something like that, is this standard practice what everyone does? It won't work on the local server though will it? Edited January 17, 2013 by 1internet Quote Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406499 Share on other sites More sharing options...
requinix Posted January 17, 2013 Share Posted January 17, 2013 Yes, it's definitely the standard way to include files. There are alternatives for different circumstances. And yes, it will work on your local server. It'll work anywhere so long as the DOCUMENT_ROOT is defined (it practically always is) and the path to the file from there is "/template.php" (it's in that directory). If your local setup is different and you need a subfolder, like "/mydomain/template.php", then it will not work because the path is different. Quote Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406520 Share on other sites More sharing options...
1internet Posted January 17, 2013 Author Share Posted January 17, 2013 right, thats what I thought. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406526 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.