在布局文件中我有
$bundle=MyAsset::register($this);
但我不知道如何在视图中使用$bundle->baseUrl
。
$bundle->baseUrl
在布局中正确运行,但如果我在视图中使用它,我会有Undefined variable: bundle
。
答案 0 :(得分:0)
由于视图是yii\web\View对象,您可以在视图文件中访问assetBundles及其baseUrls:
$this->assetBundles['yourAssetBundleName']->baseUrl;
为了完整起见,如果需要访问捆绑中的图像路径,您最好将它们放在public_html
/ webroot
文件夹中,因为无论如何它们都可以在网上看到。< / p>
答案 1 :(得分:0)