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 URL $this->backendHelper->getHomePageUrl();

Leave a Reply

Close Menu