zoukankan      html  css  js  c++  java
  • Yii 之视图数据块

    控制器代码:

       public $layout = 'common';
        public function actionStudent(){
            $data = array('page_name'=>'Student');
            return $this->render('student',$data);
        }
    
        public function actionTeacher(){
            $data = array('page_name'=>'Teacher');
            return $this->render('teacher',$data);
        }

    公共布局文件common代码:

    <!DOCTYPE html>
    <html>
    <head>
        <title>
            <?php if(isset($this->blocks['webTitle'])):?>
                <?=$this->blocks['webTitle'];?>
            <?php else:?>
                commom
            <?php endif;?>
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
    <h1>这是Common内容</h1>
    <div>
        <?=$content?>
    </div>
    </body>
    </html>

    视图student代码:

    <?php $this->beginBlock('webTitle');?>
    <?=$page_name?>页面
    <?php $this->endBlock();?>
    
    <h1> Hello <?=$page_name?></h1>

    视图teacher代码:

    <h1> Hello <?=$page_name?></h1>
    
    <?php $this->beginBlock('webTitle');?>
    <?=$page_name?>页面
    <?php $this->endBlock();?>

    总结:如果需要在视图中改变公共模板中的内容,需要使用block方法,例如上面例子中改变了common页面的title。

  • 相关阅读:
    冲刺1
    第九周
    课堂作业
    团队项目典型用户与用户场景分析
    第八周
    梦断代码阅读笔记03
    tab页的使用方法
    校园服务nabcd需求分析
    第七周
    mysql下载以及安装
  • 原文地址:https://www.cnblogs.com/gyfluck/p/9100573.html
Copyright © 2011-2022 走看看