जवाबों:
छवि यूआरएल प्राप्त करने के लिए नीचे दिए गए कोड का उपयोग करें view
<img src="<?php echo $this->getViewFileUrl('Vendor_Module::images/image.png'); ?>" />
अपडेट करें:
<?php echo $block->getViewFileUrl('images/demo.jpg'); ?>
अपने हेल्पर या नियंत्रक में छवि पथ प्राप्त करने के लिए, आपको उपयोग करने की आवश्यकता है
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\App\RequestInterface; // for $this->request
आपकी फ़ाइल में।
एक बार जब आप रिपॉजिटरी जोड़ते हैं और ऑब्जेक्ट बनाते हैं assetRepoऔर requestफ़ंक्शन के साथ इमेज पथ को कॉल करते हैं,
$params = array('_secure' => $this->request->isSecure());
$this->assetRepo->getUrlWithParams('Nitesh_Module::images/image.png', $params);
vendor\magento\module-payment\Model\CcConfig.php::getViewFileUrl($fileId, array $params = [])कार्य करना देखें
संपादित करें
सेटअप स्क्रिप्ट, एपीआई कॉल और क्रोनॉजर्स के लिए सही छवि पथ प्राप्त करने के लिए, आपको सही छवि पथ प्राप्त करने के लिए नीचे दिए गए अनुकरण को जोड़ना होगा।
public function __construct(
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\App\RequestInterface $request,
\Magento\Store\Model\App\Emulation $appEmulation
)
{
$this->assetRepo = $assetRepo;
$this->request = $request;
$this->appEmulation = $appEmulation;
}
public FunctionName($param){
$this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
$params = array('_secure' => $this->request->isSecure());
$this->assetRepo->getUrlWithParams('Nitesh_Module::images/image.png', $params);
$this->appEmulation->stopEnvironmentEmulation();
}