Use absolute or relative path?

in my config.php, where I have all the constants, I set the PATH to an absolute path.

but this means that when moving the application folder I have to change this path.

I was wondering if it is better to set the relative path, so when I move my application between the production and development folder, I do not need to change it.

how do you guys work when navigating between folders?

+5
source share
5 answers

The best way I've found is to do the following:

define("PATH", realpath(dirname(__FILE__)));

This gives you the directory of the current file. If you do this in your / bootstrap / init settings file, you will receive it in your application, and it will work for any file system.

+8

__FILE__ - .

+3
define('BASE_PATH', dirname(realpath(__FILE__)));

.

,

include BASE_PATH . 'includes/header.php';
+3

, - . , - , DreamHost . .... 14 "" : http://wiki.dreamhost.com/Server_Moves

+1

, :

  • - , dirname(__FILE__).

  • -, . : include, . , .

  • I also support user settings that relate to the installation, not the codebase. This is done using the inclusion mechanism and overrides several parameters that will be specific to the server on which the code is located.

+1
source

All Articles