Jump to content

Question about being efficient... ?


physaux

Recommended Posts

Hey guys, I was wondering if someone could advise me, here is my situation:

 

First Question:

I have my main web folder, and then 10 folders. Then in each of these 10 folders, I have 10 more folders. Ex

 

Domain.com/F8/F1

Domain.com/F8/F2

 

So, I will have many pages, and they will all have similar layout. I want to do this with php include() function, the problem is that I don't know how to "reference Up a level", like say "footer.php" was located in:

 

Domain.com/includes/footer.php

 

How would i refer to that from say Domain.com/F8/F2/index.html

Would it just be absolute path? Or is there a better way?

 

Second Question:

 

How can i pass the current path to a function? Like i mean, I want to have each file from each of those folders call a function like so:

In file- Domain.com/F2/F3/index.html

Call Function- Function(F2,F3);

How can i "send" the data of the current folder in a function?

This way I could have really efficient pages, because they would be generated from a database and just one easy-to-edit file.

 

Or again, is there a better way?

 

Thanks for any insight!!

Link to comment
Share on other sites

One option would be instead of literally creating all of these files just to fill their contents from the database, is to have only one file in the root, which would then load the contents from the db based off of the path specified in the url.  You'd have to use a series of mod_rewrites in an htaccess file to make it work, but there are plenty of examples in google to help with that.

Link to comment
Share on other sites

Question 1:  This is in the php manual spelled out really well -> http://php.net/manual/en/function.include.php

 

-If you include a path with the include (absolute or relative) it will use that to try and find the file to include. 

-If you omit the path it uses the php include path, which is set up in the php.ini.

 

In summary:

 

- include, like all the PHP file related functions, works with the *real server path*, be that absolute or relative.  Often people on hosted servers get confused about this, because they are not really aware where there web root is located.  PHP usually will provide this in the $_SERVER['DOCUMENT_ROOT'] variable, so one strategy could be to set up a BASEPATH constant or variable which is equivalent to that variable ie.

 

$basePath = $_SERVER['DOCUMENT_ROOT'];

 

Then you can specify the path to your included files using an absolute path, by concating them to the base path:

 

// You have a file that is in {webroot}/includes/ named functions.php

 

include($basePath . '/includes/functions.php);

 

Alternatively you can specify the path relatively, although this has the complexity of requiring that the script doing the include be aware of its relative relation to the included script(s).

 

Question 2:

 

Again, $_SERVER[] is your friend.

 

$urlParams = explode('/', $_SERVER['REQUEST_URI']);

 

Check out the contents of  $urlParams.

 

 

 

 

 

 

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.