I am using a self-made framework with various directories, and I would like to create a constant
which basically outputs the directory where my application folder is situated. I could accomplish this by declaring
define("DOC_ROOT", "/var/www/html/public/my-site.tld/");
somewhere in my public/index.php
file, but for some reason, I would like to use a combination of __DIR__, realpath(), dirname()...
as I still don't know why it is not working for me.
For now, let's assume this is a the folder structure I am using.
my-site.tld/
src/
public/
index.php
app/
configs/
constants.php/
views/
controllers/
bootstrap.php
Since the bootstrap.php
requires the constants.php
first, and then index.php
loads the bootstrap.php
as shown
// public/index.php
require '../boostrap.php`;
We can assume this constants are the first to run, within the application. Now, the problem is that declaring a doc root which outputs just the full path to my-site.tld or in other words
/var/www/html/public/my-site.tld/
has become impossible to me, partly because echoing DOC_ROOT
would give out different paths in different files. So, I am asking is there a way to just define DOC_ROOT
in the constants file, and wherever it is called, it will always output the main application folder as opposed to doing it manually like
define("DOC_ROOT", "/var/www/html/public/my-site.tld/");
Which require me to manually change that path everything I make changes or rename my folders.