我已经使用了有关 View 和布局的红色指南,已经在Google上进行了搜索,但是仍然无法正常工作。这是问题所在:

我想拥有2column.php和3column.php布局,它们都使用_header.php和_footer.php局部。

2columns.php布局示例:

render _header.php

$content and some other extra code

render _footer.php

无论我做什么,我都无法使其正常工作。有人可以向我发布如何实现此目标的简单示例吗?谢谢

请注意答案:

用:
<?php $this->beginContent('@app/views/layouts/header.php'); ?>
    <!-- You may need to put some content here -->
<?php $this->endContent(); ?>

不能帮我...不知道该怎么办,我不能让它做我需要的事。

最佳答案

您应该尝试:

<?php $this->beginPage() ?>
<?= $this->render('@app/views/layouts/header', $_params_) ?>

<!-- main content -->

<?= $this->render('@app/views/layouts/footer', $_params_) ?>
<?php $this->endPage() ?>

并且不要忘记在标题 View 中使用以下内容:
<head>
    <?= Html::csrfMetaTags() ?>
    <?php $this->head() ?>
    ...
</head>

阅读更多 :
  • 关于render():http://www.yiiframework.com/doc-2.0/yii-base-view.html#render()-detail
  • 关于布局:http://www.yiiframework.com/doc-2.0/guide-structure-views.html#layouts
  • 关于php - 如何创建使用页眉​​和页脚局部的布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30591691/

    10-11 03:43
    查看更多