Forum Moderators: coopster

Message Too Old, No Replies

php, templates and folder directives

best practice

         

ukgimp

9:13 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the best way of dealing with templates and the problems of includes as you navigate down the structure of a site. At the lowest level the old include works well

<?php
// Get Main Navigation
include("includes/topnav.php");
?>

Now when you move down a level :

test.com/down-a-level/

you need to have the following:

include("../includes/topnav.php");

which essentially means two templates, now if I have a third level I have to create another template.

How do you deal with such issues. I dont have the need for a fully dynamic site, I just need to get to grips with the best way of doing this before I start proper so I dont give meyself greif and woe. This is even more pertinent when working on a dev site that has a whole different folder structure. I dont want to have to go through and change all the folder paths all the time.

Cheers

Nick_W

9:16 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do this: Have a small file called ini.php in the root dir and call it on every page.


<?
## ini.php
ini_set('include_path', '/var/www/includes/');
?>

Then you only ever need do:

require('topnav.ihtml');

best practice [smarty.php.net] ;-)

Added: The nice thing about ini.php is that you can just adjust that one file when you move from your home machine to live server or vice versa

Nick

coopster

9:28 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I use a method similar to Nick_W except that I append my path to the current server path. A code snippet is in this post along with some other options (this came up just a few days ago).
[webmasterworld.com...]

ukgimp

9:48 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks

I dont have the time to learn smarty, I will though at some point.

Do you see any problems with this hack:

$root = $_SERVER['DOCUMENT_ROOT'];
$dir = "/my/dev/path/";
$path = "$root$dir";

Then when you need an include (my includes for this are above the root) you just call $path?

Cheers

Nick_W

9:57 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I dont *think* so, but why not use ini_get() - it's much simpler..

Nick

ukgimp

10:06 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>but why not use ini_get()

I never heard of it before :)

I will look into, it. Thanks.

Nick_W

10:08 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ooops! - Sorry, I meant ini_set() [dk.php.net] as mentioned above.

Nick

ukgimp

10:16 am on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lol

I did look at it before and wondered how it would help. :)

I will look again

dcrombie

12:39 pm on Nov 7, 2003 (gmt 0)



I just use:

<?PHP
include "$DOCUMENT_ROOT/includes/topnav.php";
?>

where $DOCUMENT_ROOT is supplied automatically by the server. AFAIK this works on all *ix platforms where "register_globals" and "track_vars" are set to "on".