【问题标题】:How to make 3 column layout layout in yii 2如何在 yii 2 中制作 3 列布局布局
【发布时间】:2018-01-22 08:48:14
【问题描述】:

在 yii1 中,我能够在一个页面上创建额外的布局,例如 column1、column2。 yii 1 中的旧方法不起作用。

我如何通过 yii2 实现这一点?假设页面分为 3 列,一列显示,一列显示,一列未显示。

www\center\protected\views\layout\column1.php

<?php /* @var $this Controller */ ?>
<?php $this->beginContent('//layouts/main'); ?>
<div id="content">
    <?php echo $content; ?>
</div><!-- content -->
<?php $this->endContent(); ?>

www\center\protected\views\layout\column2.php

<?php /* @var $this Controller */ ?>
<?php $this->beginContent('//layouts/main'); ?>
<div class="span-19">
    <div id="content">
        <?php echo $content; ?>
    </div><!-- content -->
</div>
<div class="span-5 last">
    <div id="sidebar">
    <?php
        $this->beginWidget('zii.widgets.CPortlet', array(
            'title'=>'Operations',
        ));
        $this->widget('zii.widgets.CMenu', array(
            'items'=>$this->menu,
            'htmlOptions'=>array('class'=>'operations'),
        ));
        $this->endWidget();
    ?>
    </div><!-- sidebar -->
</div>
<?php $this->endContent(); ?>

在 Yii 2.0 中如何实现?

【问题讨论】:

标签: yii yii2


【解决方案1】:

你可以通过这样做在 yii2 中使用布局:

1) 在 @app/views/layouts 的布局中设置您的视图,或者如果您在 moduleBasePath 中的模块中 - 视图/布局

2)

<?php
    use yii\helpers\Html;

    /* @var $this yii\web\View */
    /* @var $content string */
    ?>
    <?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <?= Html::csrfMetaTags() ?>
        <title><?= Html::encode($this->title) ?></title>
        <?php $this->head() ?>
    </head>
    <body>
    <?php $this->beginBody() ?>
        <header>My Company</header>
        <div class="span-19">
            <?= $content ?>
        </div>
        <div class="span-5 last">
            // Your code
        </div>
        <footer>&copy; 2014 by My Company</footer>
    <?php $this->endBody() ?>
    </body>
    </html>
    <?php $this->endPage() ?>

3)您可以通过添加访问布局

public $layout = 'newLayout';

在您的控制器中,或者您可以使用它的特定操作,例如

$this->layout = 'newLayout';

祝你好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多