Old 09-11-2005, 00:08   #1 (permalink)
pgo
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.
  Reply With Quote
Old 09-11-2005, 00:24   #2 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
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.
  Reply With Quote
Old 09-11-2005, 02:11   #3 (permalink)
pgo
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.
  Reply With Quote
Old 09-11-2005, 03:52   #4 (permalink)
cam
vague™
 
cam's Avatar
 
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.
  Reply With Quote
Old 09-11-2005, 04:10   #5 (permalink)
pgo
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.
  Reply With Quote
Old 09-11-2005, 07:34   #6 (permalink)
FakeFrench
Fool
 
FakeFrench's Avatar
 
Join Date: Jun 2005
Location: Finsbury Park, London
Posts: 66
If you don't use it already you may find the <base href="" /> useful.
  Reply With Quote
Old 09-11-2005, 09:50   #7 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
Quote:
Originally Posted by pgo
so if my site's root is "pgo" would this still work, or should I change it to /pgo/css/screen.css?

That should do it! no worries man, I learned this the VERY hard way, these next level up paths (../) can get confusing as hell.
  Reply With Quote
Old 09-11-2005, 09:56   #8 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
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:
NameVirtualHost * <VirtualHost *:80> DocumentRoot c:/gsgd/ ServerName test.gsgd.co.uk </VirtualHost>

i've added a rule into my hosts file

(windir)/system32/drivers/etc/hosts

like this:

Code:
127.0.0.1 test.gsgd.co.uk

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:
<VirtualHost *:80> ServerName localhost DocumentRoot c:/www </VirtualHost>

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
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8