0

I need to generate backend url with key like this:

https://m2.com/admin/test/test/index/key/123XXXX

using URL builder

$this->getUrl('test/test/index')

how can i achieve this from the frontend side ?

0

Correct me if I misunderstand your question. You want to generate a backend url and access it from frontend site, right?

In your Controller/Block class, inject \Magento\Backend\Model\Url

public function __construct(
    ...
    \Magento\Backend\Model\Url $backendUrl,
    ...
) {
    parent::__construct(...);
    $this->backendUrl = $backendUrl;
}

So you can achieve your url simply like this

// Output http://magento2.url/admin/test/test/index/key/123XXX/
$this->backendUrl->getUrl('test/test/index', ['key' => '123XXX']);
0

Try This Code

protected $HelperBackend;
protected $urlBuilder;

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

public function getCustomUrlAdmin()
{
    $admin_name = $this->HelperBackend->getAreaFrontName();
    $link = $admin_name . "/test/test/index/";
    $custom_link = $this->urlBuilder->getUrl($link);
    return $custom_link;
}

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.