0

I have to generate secure Admin URL in the frontend, for example in Magento 1.9 i can achieve it like this:

$adminUrl = Mage::getUrl('adminhtml/sales_order/view', array( 'order_id' => $order->getId()));

how can i achieve this in Magento 2.3 ?

2
0

Try this code

private $HelperBackend;
private $urlBuilder;

public function __construct(
    ............................................
    \Magento\Backend\Helper\Data $HelperBackend,
    \Magento\Framework\UrlInterface $urlBuilder,
    ............................................
  ) {
    ......................................
    $this->HelperBackend = $HelperBackend;
    $this->urlBuilder = $urlBuilder;
    ......................................
}

public function getOrderUrlAdmin($order_id)
{
    $order_id = 12;
    $admin_name = $this->HelperBackend->getAreaFrontName();
    $link = $admin_name . "/" . "sales/order/view/order_id/";
    $order_link = $this->urlBuilder->getUrl($link) . $order_id;
    return $order_link;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.