Get Free Audit

How to Get access to working directories in Magento 2.0

Oct 6, 2015

1480 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:

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


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.

Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

Post a new comment

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