Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Created June 27, 2022 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexander-Pop/70199270eb3ecc5d16067b87f5897c05 to your computer and use it in GitHub Desktop.
Save Alexander-Pop/70199270eb3ecc5d16067b87f5897c05 to your computer and use it in GitHub Desktop.
Magento 2 - get Directory Path #magento2 #routing #action #path #controller
<?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