문제

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?

도움이 되었습니까?

해결책

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top