YII学习总结5(视图)

<?php
namespace app\controllers;
use yii\web\Controller;

class HelloController extends Controller
{
public function actionIndex()
{
$hellp_str = "hello God!";

$data = array();

$data["view_hello_str"] = $hello_str;

return $this->renderPartial("index",$data);
}
}
?>


views\hello\index.php

$helper_str = "hello world!<script>console.log(111);</script>"

<?php
use yii\helpers\Html;//转义
use yii\helpers\HtmlPurifier;//过滤html

<h1><?= Html::encode($view_hello_str);?></h1> <!--Html::encode() 能防止跨站脚本攻击,转义html标签-->
<h1><?= HtmlPurifier::process($view_hello_str);?></h1>


<?= $this->render('_overview') ?><!--在一个视图中调用另一个视图-->

 禁用布局

控制器内控制 public $layout=false/'layout'
控制器成员方法内控制 $this->layout=false/'layout'
视图中选择布局 $this->context->layout=false/'layout'

 

posted @ 2016-05-17 17:30  雨落知音  阅读(201)  评论(0编辑  收藏  举报