Jump to content

Problem with includes and oragnizing of files - Need advice


fhunkydelix

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.