How to Get access to working directories in Magento 2.0

How to Get access to working directories in Magento 2.0

In Magento 1.x there is a special function for getting access to directories – Mage::getBaseDir(). In Magento 2.x it has been removed, but a whole new class has been added to fulfill the same mission. Please welcome Magento\Framework\Filesystem\DirectoryList.

Let’s take a look at the main methods of the class:

File lib/internal/Magento/Framework/Filesystem/DirectoryList.php:

One of the ways to use these functions is to declare this class in __constract:

Now you can use these methods to do the following:

– Get root Magento directory:

– Get any working Magento directory (for example ‘var’):

– Connect url to the working directory of Magento:

Here is the list of working directories available as arguments:

base, app, code, etc, lib_internal, var, cache, log, di, generation, i18n, session, media, static, pub, lib_web, tmp, sys_tmp, design, upload, view_preprocessed, html, setup.



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *