I’m using Magento 2.0.7 as I write this article and I’d like to share something I needed to implement today in one of my projects: retrieving base directories.
The process is pretty straigthforward:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$dir = $objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
// let's get the log dir for instance
$logDir = $dir->getPath(DirectoryList::LOG);
// this prints "/MAGENTO_ABSOLUTE_PATH_DIR/var/log"
echo $logDir;
Other options are:
/**
* Code base root
*/
const ROOT = 'base';
/**
* Most of entire application
*/
const APP = 'app';
/**
* Initial configuration of the application
*/
const CONFIG = 'etc';
/**
* Libraries or third-party components
*/
const LIB_INTERNAL = 'lib_internal';
/**
* Libraries/components that need to be accessible publicly through web-server (such as various DHTML components)
*/
const LIB_WEB = 'lib_web';
/**
* \Directory within document root of a web-server to access static view files publicly
*/
const PUB = 'pub';
/**
* Storage of files entered or generated by the end-user
*/
const MEDIA = 'media';
/**
* Storage of static view files that are needed on HTML-pages, emails or similar content
*/
const STATIC_VIEW = 'static';
/**
* Various files generated by the system in runtime
*/
const VAR_DIR = 'var';
/**
* Temporary files
*/
const TMP = 'tmp';
/**
* File system caching directory (if file system caching is used)
*/
const CACHE = 'cache';
/**
* Logs of system messages and errors
*/
const LOG = 'log';
/**
* File system session directory (if file system session storage is used)
*/
const SESSION = 'session';
/**
* Directory for Setup application
*/
const SETUP = 'setup';
/**
* Dependency injection related file directory
*/
const DI = 'di';
/**
* Relative directory key for generated code
*/
const GENERATION = 'generation';
/**
* Temporary directory for uploading files by end-user
*/
const UPLOAD = 'upload';
/**
* Directory to store composer related files (config, cache etc.) in case if composer runs by Magento Application
*/
const COMPOSER_HOME = 'composer_home';
Happy Coding!
courtesy: https://blog.mdnsolutions.com/magento-2-base-directories/
No comments:
Post a Comment