zoukankan      html  css  js  c++  java
  • 使用 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() ?>

    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');
    }

    表示以 mylayout.php 为布局,views/site/index.php 为内容。

  • 相关阅读:
    48. Rotate Image
    47. Permutations II
    46. Permutations
    45. Jump Game II
    44. Wildcard Matching
    43. Multiply Strings
    42. Trapping Rain Water
    Python_匿名函数
    Python_内置函数之map()
    Python_面向对象_单例模式
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/4534158.html
Copyright © 2011-2022 走看看