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));
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));
In a block, you can use $this->getUrl()
with the parameters as you know them from Magento 1. In a template, use $block->getUrl()
instead.
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 $this->urlBuilder->getUrl()
.
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.
You can use this in Magento 2 like
$block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true])