1internet Posted January 17, 2013 Share Posted January 17, 2013 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. 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. 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 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? 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. 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 Link to comment https://forums.phpfreaks.com/topic/273282-directory-structure/#findComment-1406526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.