yii2视图的创建与值的传递

来源:互联网 发布:网络系统集成建设方案 编辑:程序博客网 时间:2024/05/23 14:29

1创建视图
控制器
这里写图片描述
视图
这里写图片描述
视图的创建如上图
2.控制器中 return $this->render('index');
3.控制器和视图之间数据的传递

    $data = array();    $hellow = 'hellow word';    $data['view'] = $hellow;    return $this->render('index',$data);    4.视图的展示    <?=$key?>  ?=之间不能有空格 <?=$view?>    public $layout = 'common';//通过$layout属性去告诉render方法去显示commom布局文件    在一个视图(index)展示另一个视图(about)    $this->render('index')    视图 <?php echo $this->render('about')?>    当需要给about传值是 $this->render('about',array('key'=>'value'));    5.数据模块的展示    模板中数据块的使用(特殊模板用到)    <?php $this->benginBlock('block1');?>    <h1>要替换的内容</h1>    布局模板中的展示(判断有没有,然后在显示)    <?php    if(isset($this->blocks['blocks'])):    ?>    <?= $this->blocks['blocks'];?>    <?php else:?>    <h1>no</h1>    <?php endif;?>
0 0
原创粉丝点击