Question

How to get magento root file path in controller in Magento 2 ?

Like if my magento root file path is /var/www/html/magento in Controller file?

Était-ce utile?

La solution

You can get like this one :

protected $_dir;

public function __construct(\Magento\Framework\Filesystem\DirectoryList $dir) 
{
    $this->_dir = $dir;
}

public yourfunction()
{
   $this->_dir->getRoot(); // Output: /var/www/html/magento
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top