|
Posted by Erwin Moller on 09/26/07 08:28
Confused but working on it wrote:
> On 2007-09-25 04:31:14 -0700, Erwin Moller
> <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> said:
>
>> <snip>
>>
>> Hi Ron,
>>
>> In addition to what Jerry and Lars wrote:
>>
>> I prefer making one or two directories where I store my includes, and
>> simply add them to the include path. This makes things easy to manage.
>>
>> You can use ini_set, eg:
>> $newIncludePath =
>> get_include_path().PATH_SEPARATOR.'/home/bla/public_html/includes';
>>
>> ini_set("include_path",$newIncludePath);
>>
>>
>> You only need 1 file you include everywhere in all your scripts that
>> contains this, and you are fine.
>> If you ever move your directorytree, just adjust the path.
>>
>> Now you can simply include everything that is stored under
>> /home/bla/public_html/includes, and also its subdirectories (if you
>> name them during your include).
>>
>>
>> Regards,
>> Erwin Moller
>
Hi,
> Not sure I understand this.
Lets work on that then. :)
> Make an includes directory and put my header and footer in there plus
> any other file I make that will be includes. I can see in your example
> how this is working.
Yep.
>
> Is ini_set in my php.ini? (I don't really like to mess with this.)
No, ini_set is a way to OVERRULE whatever there is in php.ini.
You cannot overrule anything, but some things, like this, you can
overrule on a PER SCRIPT basis.
Read more here:
http://us2.php.net/manual/en/function.ini-set.php
and here:
http://us2.php.net/manual/en/ini.php#ini.list
Bottomline: You are not changing php.ini settings.
>
> So instead of:
> <?php include($_SERVER['DOCUMENT_ROOT']."includes/header.php"); ?>
> I would use?
> <?php include($newIncludePath."/header.php"); ?>
No. That is NOT what I ment.
Assuming you have a file that you include in each and every script.
This means that you include this file using ../ or ../../ or whatever
from each directory, so you are sure it is included. You have to do this
only once per file.
Now, in this include you use ini_set("include_path", .... ) as I described.
From now on you can simply include ANYTHING you cared to add to the
include path WITHOUT having to mess with its location, because it php
will always look for the file in the include_path.
So instead of using:
.... your PHP code
include("../../includes/myFooter.php");
you just say:
include("myFooter.php");
assuming that you placed myFooter.php into the includesdir.
> or:
> ???
>
> If Jerry's way works, what is the advantage?
Jerry uses $_SERVER['DOCUMENT_ROOT'].
Which is perfectly OK.
But you have to use that $_SERVER['DOCUMENT_ROOT'] every time you want
to include something.
I don't like that, that is why do it a different way, and thought I let
you know more options exists (as always).
>
> Really appreciate the help. I have a PHP MySQL book by sams and the
> don't really get into this.
Just test around a little.
It is perfectly normal to not get this immediately, simply because it is
confusing. ;-)
PS: If you already implemented it in the way Jerry suggested, and you
understand it that way: good, keep it like that. Most important thing
about coding is that YOU understand what is happening.
>
> Thanks for te hlp.
> Ron
>
Good luck.
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|