Yii2和Bundle Url

时间:2016-06-24 16:07:44

标签: php yii yii2

如果在布局中注册了不是在视图中注册的URL,我如何在视图中获取它?

在布局中我有:

use yii\helpers\Html;
use app\assets\LoginAsset;
$bundle = LoginAsset::register($this);

在我看来:

<?php
use app\assets\LoginAsset;
$bundle = LoginAsset::register($this);
?>
<img src="<?php echo $bundle->baseUrl; ?>/img/avatar-sign.png" alt="">

但我想避免重复捆绑注册,其他视图使用相同的布局,但不需要捆绑网址。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您应该只使用AssetManager::getBundle()

$bundle = Yii::$app->assetManager->getBundle('app\assets\LoginAsset');