各种render
① render使用view和layout渲染
② renderPartial只渲染view 不渲染布局 就是分配数据 不使用布局
return $this->renderPartial("@app/views/common/js.php",['msg' => $msg,'url' => $url]);
③ renderContent只渲染layout 不会作用view
renders a static string by embedding it into the currently applicable layout. This method is
available since version 2.0.1.
通过将静态字符串嵌入到当前适用的布局中来呈现它。此方法在2.0.1版之后可用。
④ renderFile显示指定的文件,是最基础的方法, renderAjax,renderPartial最终都是调用renderFile.
<?=Yii::$app->view->renderFile("@app/modules/web/views/common/tab_user.php",['current' => 'edit']);?>
此处的Yii::$app->view相当于$this(这个是yii内置的 还有$model也是内置的)
⑤ renderAjax只显示view不用布局,以ajax方式渲染页面,可以配合js/css实现各种特效
视图组件
直接使用render是简写发 ;
renderFile是完整的写法;
<?= $this->render('_overview') ?>
echo \Yii::$app->view->renderFile('@app/views/site/license.php');