Created
June 27, 2022 02:03
-
-
Save Alexander-Pop/70199270eb3ecc5d16067b87f5897c05 to your computer and use it in GitHub Desktop.
Magento 2 - get Directory Path #magento2 #routing #action #path #controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace\MyModule\Controller\Index; | |
use Magento\Framework\App\Action\Action; | |
use Magento\Framework\App\Action\Context; | |
use Magento\Framework\Module\Dir; | |
class Example extends Action | |
{ | |
public function __construct( | |
Context $context, | |
Dir $moduleDir | |
) { | |
$this->moduleDir = $moduleDir; | |
parent::__construct($context); | |
} | |
public function execute() | |
{ | |
$modulePath = $this->moduleDir->getDir('MyNamespace_MyModule'); | |
$moduleEtcPath = $this->moduleDir->getDir('MyNamespace_MyModule', Dir::MODULE_ETC_DIR); | |
$moduleI18nPath = $this->moduleDir->getDir('MyNamespace_MyModule', Dir::MODULE_I18N_DIR); | |
$moduleViewPath = $this->moduleDir->getDir('MyNamespace_MyModule', Dir::MODULE_VIEW_DIR); | |
$moduleControllerPath = $this->moduleDir->getDir('MyNamespace_MyModule', Dir::MODULE_CONTROLLER_DIR); | |
$moduleSetupPath = $this->moduleDir->getDir('MyNamespace_MyModule', Dir::MODULE_SETUP_DIR); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment