Reply to Re: Managing includes

Your name:

Reply:


Posted by Neredbojias on 06/27/07 22:22

On Wed, 27 Jun 2007 11:44:32 GMT Toby A Inkster scribed:

> Disco Octopus wrote:
>
>> You should look into the "include_path" setting in php.
>
> include_path is awesome indeed. You create a directory, put all your
> included files in there and then set the include_path for your website
> to point to that directory. (This can be set in .htaccess if need be.)
>
> Then in your code, you just reference:
>
> include "something.php";

I see no advantage to this. What is wrong with just inserting the path
as you do in a link, eg: ../par_dir/somefile.html? That way one could
address an include file anywhere on the site with a minimum of confusion
or effort. Now I realize the powers that be haven't allowed for this,
but stating an include_path is awesome seems a bit much.

> and the PHP interpreter will look to see if there is a file called
> "something.php" in your include_path. Whatsmore, your include_path can
> contain multiple paths, and your PHP script can modify it on-the-fly.
>
> For example, my CMS has this at the top of its index.php file:
>
> $ip = get_include_path();
> $dirs = array('includes', 'lib', 'PEAR');
> $base = dirname(__FILE__);
> if (!preg_match('#/$#', $base)) $base .= '/';
> foreach ($dirs as $d)
> $ip .= ':' . $base . $d . '/';
> set_include_path($ip);
>
> define('DEMIBLOG_BASE_DIR', $base);
> define('DEMIBLOG_SETTINGS_DIR', $base);
>
> This takes the path of the directory where index.php is itself
> contained, and calls that the "base" directory. It then finds
> subdirectories of the base directory called "includes", "lib" and
> "PEAR" and adds them to the include_path. It then saves the base
> directory as a PHP constant, and defines a "settings directory" which
> is the same as the base directory by default. (All other important
> directories are then loaded up as settings.)
>
> Overall, "index.php" is lean and mean: only 17 lines excluding
> whitespace and comments -- so I'm sure the fact that it dedicates over
> half of its lines to playing around with paths says something very
> profound, though I'm not entirely sure what.

Clever but cumbersome. And how many pagemakers are as adept at php as
you?

--
Neredbojias

Once I had a little bird
That made me rather hasty.
So now I have no little bird,
But it was very tasty.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация