4-1 视图之视图的创建
user yii\web\Controller;
/* 模版调用文件地址 www\basic\views\hello */
return $this->renderPartial('index');//调用模版文件
4-2 视图之数据传递
$data = array();
$hell = 'hello';
$data['hell'] = $hell;
return $this->renderPartial('index', $data);
/* 模版中php文件格式样式 */
<?=$hell;?>
4-3 视图之数据安全
/* 模版中转义代码让其显示,须在页面中调用user */
<?php
user yii\helpers\Html;
user yii\helpers\HtmlPurifier;
?>
<?=Html::encode($hell);?>//转义代码
<?=HtmlPurifier::process($hell);?>//过滤代码
4-4 视图之布局文件
/*布局文件地址*/
\basic\views\layouts
public $layout = 'common';
return $this->render('index');//$content
<?=$contnet;?>//模版文件
4-5 视图之在视图中显示另外一个视图
//views
<?php echo $this->render('index', array('1'=>'2','3'=>'3')); ?>
4-6 视图之数据块
//views
<?php $this->beginBlock('block1'); ?>
<map></map>
<?php $this->endBlock(); ?>
//布局文件
<?php $this->blocks('block1'); ?>