<?php
namespace controllers;
use yii\web\controller;
use yii\web\Cookie;
/**
* 视图的创建
*/
class HelloController extends Controdller
{
public function actionIndex()
{
return $this->renderpartial('index');
}
}
/**
* 视图的数据传递
*/
class HelloController extends Controdller
{
public function actionIndex()
{
$hello_str = 'hello God!';
$test_arr = array(1,2);
//创建一个数组
$date = array();
//把需要传递给视图的数据,放到数组当中
$data['view_hello_str']=$hello_str;
$data['view_test_arr']=$test_arr;
return $this->renderpartial('index',$data);
}
}
/**
* 视图的数据安全 javascript代码
* 完整显示出来:<h1><?=Html::encode($view_hello_str):?></h1>
* 完全去掉script代码:<h1><?=HtmlPurifier::process($view_hello_str):?>
*/
class HelloController extends Controdller
{
public function actionIndex()
{
$hello_str = 'hello God!<script>alert(3);</script>';
$date = array();
$data['view_hello_str']=$hello_str;
return $this->renderpartial('index',$data);
}
}
/**
* 视图的布局文件
* <?=$content;?>
* index视图中显示about视图:<?php echo $this->render('about',array('v_hello_str'=>'hello world!'));?>
* 其中数组中v_hello_str又可以在about视图中调用显示
*/
class HelloController extends Controdller
{
public $layout = 'common';
public function actionIndex()
{
return $this->render('index');
}
}
/**
* 视图的数据块
* <?php $this->beginBlock('block1');?>
* <h1>index</h1>
* <?php $this->endBlock();?>
*
*
* 布局文件中调用
* <?=$this->blocks['block1'];?>
*/
class HelloController extends Controdller
{
public function actionIndex()
{
return $this->render('index');
}
}
打开App,阅读手记