Easy php includes

Status
Not open for further replies.

litewarez

Active Member
1,367
2008
1
0
just like to share a tip with you for when your programming your websites etc

PHP:
//Index.php

/*
** First we need to know the exact path to where we am and define it
*/

define("APPLICATION_PATH",str_replace("\\","/",dirname(__FILE__)));

//then we need tell PHP to add our includes path to there own

$current_paths = get_include_path();
$new_paths = array($current_paths,APPLICATION_PATHS  "/includes/");
set_include_path(implode(PATH_SEPARATOR,$new_paths));

/*
** No usually you will have to include your files like so
** include 'includes/myfile.php';
** but we can include as below
*/

require_once('myfile.php');

//This way it will search for myfile.php in all the paths you add into the above array :)
 
4 comments
Yes desi boy i use that define in every script i build... its nix compatible and never faild me :D

Also use the autoload feature along side this aswell for using non-public php includes

function __autoload($Class,$args){
include "../../system/"strtolower($Class) . ".php";
return new $Class($args);
}

:D
 
Status
Not open for further replies.
Back
Top