sogura 2013-04-20 00:31:13 2874次浏览 3条回复 0 0 0

原来在PHP 中通过 include 包含页头,页脚的做法,在Yii 中是要如何做呢? 包含输出HTML的和包含纯粹php 功能代码的分别是如何呢?

  • 回复于 2013-04-20 00:35 举报

    在Yii中的html布局是基于layout的,你可以看一下官方blog的demo。

  • 回复于 2013-04-25 13:19 举报

    我调成Yii 的包含方式出现如下的错误

    Undefined variable: content
    04 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    05 <meta http-equiv="content-language" content="zh-cn" />
    06 <!--#include virtual="inc.head.php"-->
    07 <title></title>
    08 <style type="text/css">
    09 </style>
    10 </head>
    12 <body>
    13     <div id="wrapper">
    14 
    15  <?php $this->beginContent('/layouts/inc.header'); ?>
    16  <?php echo $content; ?>
    17 <?php $this->endContent(); ?>
    18         <div id="main">
    19             
    20         </div>
    21         <div id="functionalhtml">
    22         
    23         </div>
    24          <?php $this->beginContent('/layouts/inc.footer'); ?>
    25  <?php echo $content; ?>
    26 <?php $this->endContent(); ?>
    27     </div>
    28 </body>
    
  • 回复于 2013-04-25 13:20 举报

    inc.header.php 和inc.footer.php 里面就只是静态的HTML代码,并且我在SiteController.php 中增加了一个
    function actionMain(){ $this->render('main');} 的action

您需要登录后才可以回复。登录 | 立即注册