The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20160322

PHP INCLUDE/REQUIRE PATH SCHEME

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 :)


<?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 {
// ...
}