Can I call Mage::getUrl() directly using $this-> in Magento2?
How can I use below code in Magento2?
$link = Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$this_params));
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 community
In a block, you can use
$this->getUrl() with the parameters as you know them from Magento 1. In a template, use
Outside blocks and templates, you need access to
\Magento\Framework\UrlInterface, so if it is not available yet in the current class, add it as a constructor parameter, assign it to
$this->urlBuilder, then use
You can simply call this method in magento 2 using below way,
//define query array pass to url $query = ['str1' => 'value1', 'str2' => 'value2',]; $link = $block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
You can also pass action value instead of
*/*/* in above url, like 'customer/account/login' as per your required action.