我是新手。我试图在布局内嵌套布局,但它不工作
布局主(包含导航栏)
<?php $this->beginBody() ?>
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
.............................
];
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<?php $this->endBody() ?>
另一个布局应用程序
<?php $this->beginPage('//layouts/main') ?>
<?php $this->beginBody() ?>
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<div class="container">
<?= $content ?>
</div>
</div>
</div>
</div>
<?php $this->endPage() ?>
在控制器中,我渲染了applicationLayout,但它不显示主布局,也就是说它不显示导航栏
您必须使用<?= $this->render('//layouts/main') ?>
或<?php echo $this->render('//layouts/main') ?>
检查路径是否正确