I am working on my first MVC base and want to define 4 constants for BASE_PATH, APP_PATH, LIB_PATH and PUBLIC_PATH. My file structure is as follows:
/ /app /controllers /models /views /config /db /lib /public_html /css /js /img
My index.php file is in the public_html directory. And currently has the following code:
error_reporting(E_ALL); define('BASE_PATH',dirname(realpath(__FILE__)) . "/../"); define('APP_PATH',dirname(realpath(__FILE__)) . "/../app/"); define('LIB_PATH',dirname(realpath(__FILE__)) . "/../lib/"); define('PUBLIC_PATH',dirname(realpath(__FILE__)) . "/"); require LIB_PATH . 'core.php';
It works, but I feel that there should be a better way to do this without all the "..". Any suggestions or is this the best way around this? Let me know. Thanks!
ANSWER
Thanks @fireeyedboy and @KingCrunch, I came up with the solution I was looking for. This is my last code:
define('PUBLIC_PATH', dirname(__FILE__) . "/"); define('BASE_PATH', dirname(PUBLIC_PATH) . "/"); define('APP_PATH', BASE_PATH . "app/"); define('LIB_PATH', BASE_PATH . "lib/");
source share