paths can b copied to any file n will work, w/o needing to b changed--
as long as the __ROOT__ variable is properly configured at the top of the file u paste into :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// /myproject/includes/phpIncludeRequirePathScheme.php | |
/* | |
a path-include/require-scheme that will work everywhere. | |
paths can b copied to any file n will work, w/o needing to b changed-- | |
as long as the __ROOT__ variable is properly configured at the top of the file u paste into | |
(i.e. choose the correct SUBLEVEL “define” code example below). | |
author: nickleus | |
date: 20160322 | |
*/ | |
/* | |
PATH EXAMPLES FOR MYPROJECT ROOT DIR | |
'__ROOT__' always returns: '/myproject' | |
// SUBLEVEL 0 (MYPROJECT ROOT DIR) | |
// this php file: /myproject/thisfile.php | |
define('__ROOT__', __DIR__); | |
// SUBLEVEL 1 | |
// this php file: /myproject/subfolder/thisfile.php | |
define('__ROOT__', realpath(__DIR__.'/..')); | |
// SUBLEVEL 2 | |
// this php file: /myproject/subfolder/subfolder/thisfile.php | |
define('__ROOT__', realpath(dirname(__DIR__).'/../..')); | |
// SUBLEVEL 3 | |
// this php file: /myproject/subfolder/subfolder/subfolder/thisfile.php | |
define('__ROOT__', realpath(dirname(dirname(__DIR__)).'/../../..')); | |
...etc... | |
*/ | |
// SUBLEVEL 1 | |
// this php file: /myproject/includes/phpIncludeRequirePathScheme.php | |
define('__ROOT__', realpath(__DIR__.'/..')); | |
require_once __ROOT__.'/includes/file1.php'; | |
include_once __ROOT__.'/models/file2.php'; | |
require_once __ROOT__.'/utils/file3.php'; | |
include_once __ROOT__.'/file4.php'; | |
class Example { | |
// ... | |
} |