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 ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI 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 ?
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']);
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;
}