Get admin URL in Magento 2

We can use \Magento\Backend\Helper\Data class to get Admin Url. /** * @var Magento\Backend\Helper\Data */ private $backendHelper; public function __construct( ... \Magento\Backend\Helper\Data $backendHelper ... ) { ... $this->backendHelper = $backendHelper; ... } public function getAdminUrl() { retrun $this->backendHelper->getHomePageUrl(); } You can get admin URL by getHomePageUrl() function of backend helper class Here you will get admin…

Continue Reading Get admin URL in Magento 2
How to check if the current area is frontend or backend?
How to check if the current area is frontend or backend?

How to check if the current area is frontend or backend?

Use Magento\Framework\App\State class to get the area code of the current page. I will show you how you can get the current area by object manager and with dependency injection. With ObjectManager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $state = $objectManager->get('Magento\Framework\App\State'); echo $state->getAreaCode(); With Dependency Injection: protected $_state; public function __construct ( \Magento\Framework\App\State $state ) { $this->_state =…

Continue Reading How to check if the current area is frontend or backend?