Magento 2 Get file URL of the static content folder in Controller

0
77
views
Magento 2 Get file URL of the static content folder in Controller
Advertisement
<?php
class ...

protected $_assetRepo;

public function __construct(
    ....
    MagentoFrameworkViewAssetRepository $assetRepo,
    ....
) {
    ....
    $this->_assetRepo = $assetRepo;
    ....
}

Now, In you case module name is : Company_Helloworld and you want icon.png from images directory so 

echo $this->_assetRepo->getUrl("Company_Helloworld::images/icon.png");

Hope this will help you.