如何禁用某些控制器 yii2 的面包屑导航?

how to disable breadcrumb for some controllers yii2?

我想在 Yii2 应用程序中禁用或更改面包屑导航。怎么做 that.I

tried to change with

echo Breadcrumbs::widget([
    'itemTemplate' => "<li><i>{link}</i></li>\n", // template for all links
    'links' => [
        [
            'label' => 'Post Category',
            'url' => ['post-category/view', 'id' => 10],
            'template' => "<li><b>{link}</b></li>\n", // template for this link only
        ],
        ['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]],
        'Edit',
    ],
]);

嗯,首先把它改回默认值,也就是:

<?= Breadcrumbs::widget([
    'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

根据 yii2 documentation 如果您将 $links 的值设置为空数组,面包屑将不会显示。

你是怎么做到的?
检查上面的代码,$links 值由 $this->params['breadcrumbs'] 变量设置,每个 view 文件都可用。所以在你的视图文件中这样做:

// empty if you don't want breadcrumbs
$this->params['breadcrumbs'] = [];

否则设置一些值,你的面包屑就会出现。