Get Current Admin User Role id programmatically in Magento 2.

Magento 2 Contains Multiple Users for the admin panel to access different sections of the functionality based on their User Roles.

You can see User Roles in the admin panel by clicking on the left navigation System -> Permissions -> User Roles. Continue reading “Get Current Admin User Role id programmatically in Magento 2.”

How to get backend Url in Magento 2?

It’s quite easy to fetch Base URL for an Admin panel/Backend in Magento 2 using Backend module Url Class.

Back end Url have base store Url plus admin URI name. like {BASE_URL}/admin/

You can get Magento2 backend URL by just below way,

public function __construct(
    \Magento\Backend\Model\Url $backendUrlManager
) {
    $this->backendUrlManager  = $backendUrlManager;
}

public function getBackendUrl()
{
    return $this->backendUrlManager->getUrl('sales/order/view', ['param1' => 'param1']);
}

We have passed Sales/order/view action with a query string as param1 in URL.

Get URL from an adminhtml template or PHP file,
echo $this->getBackendUrl();