fhunkydelix Posted August 25, 2010 Share Posted August 25, 2010 Hello, I have a serious problem with includes So in the past I didn't have any organizing done when creating a website it was just the root and I throw in my files and a folder for the images. Now I am organizing my files something like this http://www.flickr.com/photos/41987677@N03/4926503042/. Now in index.php on the root folder I included the top.php, bottom.html and sessions.php as seen on global folder and inside of top.php and session.php are more includes to files like global.css the javascript files and images like logo and background of the top. now everything worked fine on index.php(root) and displayed everything. Now under the karoobridge folder (index.php) I included the top and bottom files on global now its throwing an error. My question is: is the organization I'm using useless with includes should I stick with just throwing everything on root directory? Can you give me some advice? Sorry if my explanation is confusing but I think you get the idea. I also tried $_SERVER["DOCUMENT_ROOT"] and put that in the index of karoobridge folder to get the top.php, though i got the file the image in top.php didn't appear (I also used $_SERVER['DOCUMENT_rOOT'] for the images) what could be the problem? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 25, 2010 Share Posted August 25, 2010 There are different ways to organize, but I prefer using a front controller, an index.php in the root dir that is always loaded first. This index.php will then make the determination of what other files to include, whether they be in the root or another dir. This makes includes very simple because everything is relative to the root indexd.php. The problem with loading and index.php from another dir directly is that all subsequent includes will be relative to that file. This is very difficult to maintain. Quote Link to comment Share on other sites More sharing options...
fhunkydelix Posted August 25, 2010 Author Share Posted August 25, 2010 There are different ways to organize, but I prefer using a front controller, an index.php in the root dir that is always loaded first. This index.php will then make the determination of what other files to include, whether they be in the root or another dir. This makes includes very simple because everything is relative to the root indexd.php. The problem with loading and index.php from another dir directly is that all subsequent includes will be relative to that file. This is very difficult to maintain. So what do you suggest? get rid of the idea making each subdirectories into folders? and just throw it all into the root? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 25, 2010 Share Posted August 25, 2010 There are different ways to organize, but I prefer using a front controller, an index.php in the root dir that is always loaded first. This index.php will then make the determination of what other files to include, whether they be in the root or another dir. This makes includes very simple because everything is relative to the root indexd.php. The problem with loading and index.php from another dir directly is that all subsequent includes will be relative to that file. This is very difficult to maintain. So what do you suggest? get rid of the idea making each subdirectories into folders? and just throw it all into the root? No, I suggested having one index.php in the root that then can include other files in other directories. There are many ways, here is just an example: /index.php ------------------/karoobridge/ --------------------------index.php ------------------/someotherdir/ --------------------------index.php etc... Now you would always load the root index.php and if it was http://example.com/index.php?dir=karoobridge, then the root index.php would load the karoobridge/index.php. With URL rewriting you could get the URL to look like just http://example.com/karoobridge. Another way would be to have a content dir with the named files: /index.php ------------------/content/ --------------------------karoobridge.php --------------------------someother.php etc... 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.