| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Directory Structure Problem
On most sites, I use PHP includes to pull in repeated bits of code and "if" statements in conjunction with variables for things like "current" navigation items. The biggest problem I run into is getting to certain static files - like my CSS file. This wouldn't be a problem, except I like to keep clean URLs (www.somesite.com/blah/). Usually, I do this my creating the directory and putting an "index.php" file in it. The problem is, when you have different directory levels - let's say three levels (root, lvl1, lvl2). The root index.php file might have the location for its CSS as "css/screen.css". But The lvl1 directory index.php files would need "../css/screen.css" and then "../../css/screen.css" and so on and so on. This can get confusing fast. So, I'm looking for tips on using PHP and includes as basic flat-file content management. Much thanks in advance. |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
|
relate your css to the root of your site. instead of ../.../../../../ just use /css/screen.css. That first backslash will locate your root folder then dive from there to where ever your css is at. Then every file will look in the same place and find it. |
|
|
|
#3 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Really? I didn't know that. How does it define the root directory? I only ask because when I develop locally, I usually put each site in its own directory within the Apache root - let's say "pgo" in "htdocs" (which is XAMPP's root Apache directory, I believe) - so if my site's root is "pgo" would this still work, or should I change it to /pgo/css/screen.css? Anyway, thanks for the tip. Made me feel like an utter tool, but appreciated nonetheless. |
|
|
|
#4 (permalink) |
|
vague™
Join Date: Mar 2004
Location: Glasgow
Posts: 5,555
|
Something to think about in the future is only using one php file to serve content (index.php) and using friendly url's (via apache's rewrite mod) to pass parameters into that one php file which let it decide what content to retrieve. That, in association with a templating engine (we use Smarty) would make site building and maintenance far quicker than doing it manually. |
|
|
|
#5 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Gotcha. I'll look into mod_rewrite for the site I'm working on at the moment (which, working manually, is getting to be a pain in the butt because it's got at least a dozen pages with more on the way). And I've looked at Smarty before - but only briefly. Thanks cam. |
|
|
|
#6 (permalink) |
|
Fool
Join Date: Jun 2005
Location: Finsbury Park, London
Posts: 66
|
If you don't use it already you may find the <base href="" /> useful. |
|
|
|
#7 (permalink) | |
|
Senior Member
|
Quote:
That should do it! no worries man, I learned this the VERY hard way, these next level up paths (../) can get confusing as hell. |
|
|
|
|
#8 (permalink) |
|
hmmm...
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
|
If you're testing locally, you need to try and get your head round virtualhosts in apache. I use the following for gsgd.co.uk In my apache config. Code:
i've added a rule into my hosts file (windir)/system32/drivers/etc/hosts like this: Code:
I can then access my local gsgd by using test.gsgd.co.uk. But it'll also reroute localhost. So to get that back I need this in apache.conf Code:
You can pretty much set up as many as you need. Works for any local apache, osx hosts file is in \etc\ i think. Only other gotcha is that if you're using a proxy server, you'll need to bypass for your test address otherwise it'll try and access it via the proxy and that won't work |
|
![]() |