首页 > IT职业 > IT职场 > yii框架基础篇之视图操作
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代码
* 完整显示出来:=Html::encode($view_hello_str):?>
* 完全去掉script代码:=HtmlPurifier::process($view_hello_str):?>
*/
class HelloController extends Controdller
{
public function actionIndex()
{
$hello_str = 'hello God!';
$date = array();
$data['view_hello_str']=$hello_str;
return $this->renderpartial('index',$data);
}
}
/**
* 视图的布局文件
* =$content;?>
* index视图中显示about视图: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');
}
}
/**
* 视图的数据块
* beginBlock('block1');?>
* index
* endBlock();?>
*
*
* 布局文件中调用
* =$this->blocks['block1'];?>
*/
class HelloController extends Controdller
{
public function actionIndex()
{
return $this->render('index');
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3313/viewspace-2807968/ ,如需转载,请注明出处,否则将追究法律责任。