Magento2 get admin url

Magento2 get admin URL

Magento2 get admin url.If   want to get admin URL to Magento 2 then you can try below Solution

In order to get admin  URL ,you need to inject the  Magento_Backend ‘s helper class Magento\Backend\Helper\Data  to  __construct() function.

    /**
     * @var Magento\Backend\Helper\Data
     */
    protected  $HelperBackend;
    public function __construct(
	....
	\Magento\Backend\Helper\Data $HelperBackend
	....
    ) {
	...
	$this->HelperBackend = $HelperBackend;
	...
    }

    /**
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function getAdminUrl()
    {
	echo $this->HelperBackend->getHomePageUrl();
    }

 

Here you will get  Magento 2 get admin url from getAdminUrl() which basically return

Magento_Backend module’s  getHomePageUrl() function, This function also given admin home page url.

Magento2 get admin URL