Forum Moderators: coopster

Message Too Old, No Replies

Problem with my includes and structure

         

TheRookie

2:09 am on Apr 3, 2005 (gmt 0)

10+ Year Member



Alright, I'm sure there is a simple fix for this, but I'm pretty clueless. My structure for my site is like this:

In my main directory, I have:

index.php
Articles (a folder), which has main.php
Includes (a folder)

In includes, I have header.php and footer.php, which I have my index point to with:

<?php
include 'includes/footer.php';
?>

However, with main.php in the Articles folder, I think it's looking for an includes folder in the Articles folder. What do I need to do for the includes on main.php to tell it that the folder is in the main directory, and not in the Articles folder?

Sorry if this doesn't make ANY sense, but it's tough to put the problem into words. Thanks for any help.

bluedalmatian

4:57 am on Apr 3, 2005 (gmt 0)

10+ Year Member



Either use ../ to make it look in the parent directory - the problem with that is if your site gets anymore complicated that sort of path notation can get unweildy.

I prefer to specify it as a url eg Include ("www.yourdomain.com/include/.....");

There may be a better way. If there is I'm as keen to know as you!

TheRookie

5:22 am on Apr 3, 2005 (gmt 0)

10+ Year Member



I was originally going to just put the URL, but I plan on switching domain names soon, so I needed a different way. The "..\" is perfect, though. Thanks!

killroy

10:49 am on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a way to define an absolute path relative to the docroot? like '/include/' meaning include folder off the docroot rather then the drive root.

SN

Longhaired Genius

12:05 pm on Apr 3, 2005 (gmt 0)

10+ Year Member



I don't think there is. My solution is to have a variable "$site" which is the path from the drive root to the docs folder of the site. Then my internal php urls are of the form: ($site . '/include/'). So if I had to change servers I would just have to change the content of the variable "$site". I'd be interested to hear of any other solutions.

coopster

12:13 pm on Apr 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at message #17 and see if it is what you are looking for...

It's the Good PHP solutions to small problems [webmasterworld.com] thread in our PHP Forum Library.

ergophobe

6:36 pm on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Jane, you ignorant... I guess SNL quotes violate the rules.

Anyway, for a dissenting view.... see the last three paragraphs of
[webmasterworld.com...]

coopster

11:22 am on Apr 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I wouldn't argue with the dissenting view as managing a larger application no doubt has a balance. However, hard-coding include paths versus a variable include path is definitely a programmer's discretion and design. I tend to design as such and manage from the beginning. If I haven't had control from the very beginning (been asked to maintain or add to an existing site) I know that PHP has offered many different ways to deal with these issues too, classes being one of the more obvious. There are, of course, many, many different ways to manage the include path. How to do so is a challenge for everyone ;-)

TheRookie, this thread may help you understand how PHP processes an include():

include path error... [webmasterworld.com]

killroy

12:10 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I want to know is, where is the best place to place a little library of usefull functions that I want to use in all my sites?

SN

ergophobe

6:33 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



killroy,

As the number of sites on my development platform grows, I'm thinking I also need to streamline this in some intelligent way. The part I haven't figure out is, when I upgrade a tool, how do I synch all live sites that tool has been used on?

As for development, though, since I'm using virtual hosts on my development machine, my dir structure is like this

htdocs

->site1
-> ->www
-> ->other

->site2
-> ->www
-> ->other

->tools

so from DOC_ROOT and server root for a given site, the path to tools is

DOC_ROOT/../../tools/

which means that the path won't necessarily be the same on a live server (I have two sites I've worked recently on where the account does not even have access outside of web root). That can be handled fine with path constants, but lately I'm trying to just mirror the live and local sites on virtual servers, and that model breaks down in the example just given. I just recently learned that windows (I use Win2K for my workstation) can do symlinks. So I think what I'll do in the future is something like this

htdocs
>site15
>>www
>>tools

and >>tools will use a symlink to the actual tools repository. Otherwise live sites would either require
- a different config file than the local site and that gets confusing
- live sites would be constrained by the file setup on my development platform and that makes no sense either.

Since I haven't done this yet, I'd definitely care to hear dissenting opinions on that too!

On symlinks under windows (called junction points)

[support.microsoft.com...]

See also the user notes at

[us4.php.net...]

killroy

9:52 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, if symlinks pose a problem you can always map the tools folder as a network drive, like x:\ and refer to x:\ for the tools.

SN

ergophobe

4:56 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'll keep that in mind... maybe. Would that work just like a symlink (in other words, it would be transparent to the script that the direcotry I call is just shunting it off to somewhere else)?