您的位置:首页 > 编程语言 > PHP开发

yii-besic (六) 视图布局传值

2016-12-12 16:56 363 查看
(一)//调用视图层(布局)

     public $layout='index'; 

//目录为/views/layouts/index.php

/*

*视图层内容为

*<!doctype html>

*<html lang="en">

*<head>

*     <metacharset="UTF-8">

*    <title>Document</title>

*</head>

*<body>

*<h1>1111</h1>

*<?=$content;?>

*</body>

*</html> 

*/

//调用视图层(传值)

     public  function actionAbout(){

          $data=array('name'=>'aaaaa');

           return$this->render('index',$data);

     }

 

//(二)调用中显示灵位一个视图(传值)

Index.php

<h1>hello index</h1>

<?php echo $this->reader(‘about’,array(‘name’=>’zhangsan’)) ?>

About.php

<h1>hello about</h1>

<?=$name?>

 

(三)数据块

Layout 文件

<?php if(isset($this->blocks[‘block1’])): ?>

              <?=$this->blocks[‘block1’]?>

       <?php else:?>

              <H1>hellocommen</h1>

<?php endif; ?>

<?=$content;?>

Index.php

<h1>hello index</h1>

替换layout中的内容

<?php $this->beginBlock(‘block1’) ;?>

<h1>about</h1>

<?php $this->endBlock(); ?>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: