Re: Path question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 28, 2011 at 09:18:39PM -0400, Jack wrote:

> Hello All,
> 
>  
> 
> Is there a smarter way to do includes by setting up a path or something
> where I don't have to include /home/domain.com/includes/include_file.php
> 
> Apparently my path is as shown above,  but I would prefer to just put in
> /includes/include_file.php
> 

As a first action, in whatever file you first include or call, do the
following:

$site_path = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
define ('SITE_PATH', $site_path);

Next, create a function like:

function include_path($filename)
{
	$str = SITE_PATH . 'include' . DIRECTORY_SEPARATOR . $filename;
	return $str;
}

Now, when you want to include a file, do

include(include_path('something.php'));

In my projects, I have a variety of directories, like libraries, views,
models, etc. So the function I use has a second parameter:

include(fullpath('model', 'pizza.php'));
include(fullpath('include', 'gesundheit.php'));

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux