Page 1 of 1

Dynamic absolute path for includes/requires

Posted: Sun May 26, 2013 6:12 am
by Qphoria
I've made my case a few times to theme makers that prefer to split off parts of pages and call them with their own

Code: Select all


But that breaks it when using vQmod because it assumes the relative path. And since vQmod changed files run out of the vqcache path, the solution is to use the full absolute path to where it "should" be, but to be sure it is dynamic per site.
I always used the following:

Code: Select all

include(DIR_SYSTEM . '../path/to/file/xxx.php');
as that will use the DIR_SYSTEM path which is guaranteed to exist and be constant among all opencart stores.
I include the '../' to tell the code to go up one level which is the parent directory of the "system" folder
That is the guaranteed way to find the root folder of the cart. From there you can build the path to your file. Alternatively you can use:

Code: Select all

include(dirname(DIR_SYSTEM) . '/path/to/file/xxx.php');
which functionally does the same thing.

But aside from making it work with vQmod, it also has its other benefits from a code perspective shown here: ... e-php.html

Read down to the "a better approach" part....

So not only does it make it vQmod compatible, it also speeds things up a tad