在 Yii2 中对页面进行不同布局的最佳做法是什么? 我面临的问题是 Yii2 layout/main.php 代码看起来像
<div class="container">
<?= $content ?>
</div>
Yii2 使用 Bootstrap,我只需要在 site/index.php 中制作全宽图像。 基本上在 index.php 中我需要包装
<?= $this->render('_search') ?>
进入.container-fluid 类。
如何仅将 index.php 页面的 .container 类替换为 .container-fluid 类?
最佳答案
制作一个新的布局,例如layout-fluid.php
,在controller中做
public function actionIndex()
{
$this->layout = 'layout-fluid';
return $this->render('index');
}
如果流体容器是您唯一需要的改变,您可以改为这样做:在索引 View 文件中添加
$this->params['fluid'] = true;
然后在布局文件中将所需的容器更改为
<div class="container<?= $this->params['fluid'] ? '-fluid' : '' ?>">
params
数组是在 View 中传播信息的好地方。
关于html - index.php 中的 Yii2 全 Angular 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745513/