off*_*ine 5 php layout view yii2
我有关于视图和布局的指南,我已经用Google搜索了这个,但我仍然无法使其工作.这是问题所在:
我想要2column.php和3column.php布局,两者都使用_header.php和_footer.php部分.
2columns.php布局示例:
render _header.php
$content and some other extra code
render _footer.php
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我都无法发挥作用.有人可以给我发一个如何实现这个真正简单的例子吗?谢谢
请注意答案:
使用:
<?php $this->beginContent('@app/views/layouts/header.php'); ?>
<!-- You may need to put some content here -->
<?php $this->endContent(); ?>
Run Code Online (Sandbox Code Playgroud)
不帮助我...不知道该怎么做,我不能让它做我需要的.
你应该尝试:
<?php $this->beginPage() ?>
<?= $this->render('@app/views/layouts/header', $_params_) ?>
<!-- main content -->
<?= $this->render('@app/views/layouts/footer', $_params_) ?>
<?php $this->endPage() ?>
Run Code Online (Sandbox Code Playgroud)
并且不要忘记在标题视图中使用以下内容:
<head>
<?= Html::csrfMetaTags() ?>
<?php $this->head() ?>
...
</head>
Run Code Online (Sandbox Code Playgroud)
阅读更多 :
render():http://www.yiiframework.com/doc-2.0/yii-base-view.html#render()-detail