How to get base URL , media URL and link URL via Factory method ?

How to get base URL , media URL and link URL via Factory method ?

Block file :

namespace Test\Module\Block;

class Product extends \Magento\Framework\View\Element\Template

{

protected $storeManager;

public function __construct(

\Magento\Framework\View\Element\Template\Context $context,

\Magento\Store\Model\StoreManagerInterface $storeManager

) {

$this->storeManager = $storeManager;

parent::__construct($context);

}

public function getBaseUrl()

{

$currentStore = $storeManager->getStore();

return $currentStore->getBaseUrl();

}

public function getMediaUrl()

{

$currentStore = $storeManager->getStore();

return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);

}

public function getLinkUrl()

{

$currentStore = $storeManager->getStore();

return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);

}

}

Phtml file :

echo $this->getBaseUrl();

echo $this->getMediaUrl();

echo $this->getLinkUrl();

?>



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.