in my config.php where i have all constants i set the PATH to a absolute path.
but this means that when i move my application folder i have to change this path.
i wondered if its better to set a relative path, in that way whenever i move my application between production and development folder, i dont have to change it.
how do you guys do when you move between folders?
When a user clicks a relative link, the browser takes them to that location on the current site. For that reason, you can only use relative links when linking to pages or files within your site, and you must use absolute links if you're linking to a location on another website.
Relative paths rely on the current working directory. This is a form of global state, and as such it should be avoided whenever possible. Depending on the structure of your application, the current working directory may not be guaranteed to be constant through all code paths that can reach a certain routine.
Creating an absolute path for connecting different websites Whether the link opens in a tab or a window depends on the user's browser settings. On the other hand, relative links connecting pages within your own website should always load in the same browser page.
Using relative paths is a good coding practice regardless of the language or program in which you are coding. It allows for portability of the code between directory locations on a single machine, or if copied or accessed on multiple machines.
The best way I've found is to do the following:
define("PATH", realpath(dirname(__FILE__)));
That gives you the directory of the current file. If you do this in your settings/bootstrap/init file, you'll have it available to your application, and it will work for any file system.
__FILE__
is your friend.
define('BASE_PATH', dirname(realpath(__FILE__)));
This will make your scripts more portable.
Include a file like this
include BASE_PATH . 'includes/header.php';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With