Get Free Audit

How to Get access to working directories in Magento 2.0

Oct 6, 2015

1327 Andrei Danilchyk

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:

Vlad Yunusov
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Vlad

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.

Vlad Yunusov
Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Vlad

Post a new comment

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