Yii2:如何将某些东西放入面包屑小部件中?

Yii2: How can I place something into a Breadcrumbs widget?

我不知怎么找到了小部件的 Breadcrumbs widget quite useful. However, on the right side within the widget there is enough space for something else. If I'd like to put a link ('a' tag, but could be actually any other small thing) right aligned into the Breadcrumbs, how could I do that? What is a simple and proper solution? Should I extend the class, develop my own, use begin and end

如果您查看 yii\widgets\Breadcrumbs,您会发现面包屑项中有第三个参数

来自 Yii2 文件

   [
       'label' => 'Post Category',
       'url' => ['post-category/view', 'id' => 10],
       'template' => "<li><b>{link}</b></li>\n", // template for this link only
   ],

因此,在您的主布局文件中添加类似这样的内容

$this->params['breadcrumbs'][] = [
    'label' => 'Your Label', 
    'url' => ['controller/action'], 
    'template' => "<li style="float: right;">{link}</li>\n"
];

你会在右边得到一个link。此 link 将带有 / 前缀,但您可以将其绑定到 .class 并按照您想要的方式进行配置。

'template' => "<li class=\"yourClass\">{link}</li>\n"