zoukankan      html  css  js  c++  java
  • YIi 使用 beginContent() 和 endContent() 设定 Yii 的 layouts

    Yii 的 views/layouts 是用来放置 layouts 的目录,在默认的情况下会有 main.php 和 column1.php 和 column2.php。

    main.php 内容定义了,<head> 以及 page header 和 footer 等。 column1.php 和 column2.php 是使用 main.php 的网页布局,但修改内容的部份。

    例如,我们有个 layout 叫做 mylayout.php:

    <?php $this->beginContent('//layouts/main'); ?>
    <div>
        <?php echo $content ?>
    </div>
    <div class="sidebar">
        <ul>
            <li>option 1</li>
            <li>option 2</li>
        </ul>
    </div>
    <?php $this->endContent() ?>
    (输出$content内容,增加另外的div内容输出)

    beginContent(‘//layouts/main’) 表示以 main 为布局,在  beginContent() 和 endContent() 之间为 content 呈现的修改。 beginContent() 和 endContent() 之外的范围不建议加入 HTML,否则会在 main.php 内容的前面或后面(<html> 标签之前或 </html> 标签之后)。

    在 controller 里可以这样使用:

    public function actionMylayout() {
        $this->layout = 'mylayout';
        $this->render('//site/index');
    }
    转自:http://iteches.com/archives/63580
  • 相关阅读:
    括号序列
    单向TSP
    Black Box
    震惊!!!某初中生竟30min一蓝两紫一黑!!!
    荷马史诗
    SUFEQPRE
    UVA劲歌金曲
    UVA城市里的间谍
    饼图----插件
    折线图-----插件
  • 原文地址:https://www.cnblogs.com/youxin/p/3822636.html
Copyright © 2011-2022 走看看