Pages

Saturday, September 5, 2015

Magento 2: get the Current Url

We can use below syntax to get current Url:

protected $_urlinterface;

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\UrlInterface $urlinterface,
array $data = []
) {
parent::__construct($context, $data);
$this->_urlinterface = $urlinterface;
}


public function getCurrentUrl()
{
return $this->_urlinterface->getCurrentUrl(); // Give the current url of recently viewed page
}

No comments:

Post a Comment