How to get Base Url and Current Url Magento 2?

In Magento 2, You can get Base Url, Current Url, get Media URL, get static page URL and custom URL using Magento\Store\Model\StoreManagerInterface and Magento\Framework\UrlInterface Object.

Using StoreManager Object,
Create PHP file and Passed Dependency injection Magento\Store\Model\StoreManagerInterface,

Call in Template file,

Call In template file,

You can add a Query parameter in URL,
// You can set query parameter using
$url = $this->urlBuilder->setQueryParam(‘query1’, ‘value1’);

if you want to pass multiple query parameter you need to call again above line,

echo $block->getQueryParameter();
Output:
http://www.rjesadiya.com/default/catalogsearch/result/index/?query1=value1&query2=value2

Leave a Reply

Your email address will not be published. Required fields are marked *