crowprince 2016-08-05 10:33:39 6425次浏览 2条评论 2 0 0

1.先在控制器中保存参数

public function actionAbout()  
{  
    $view = Yii::$app->getView();//此处的view实例与视图中的view(默认的$this变量)为同一个。所以此处保存的参数在视图中也可以用  
    $view->params['testView'] = 'testView'; //因为是同一个布局变量,所以在视图中也可以使用  
    //$this->renderAjax('about',['test'=>7]);  
    //$this->renderFile('app\views\site\about.php',['test'=>8]);  
    return $this->render('/site/about.php',['test'=>5]);  
}  

2.在view中使用它

echo $this->params['testView'];

我的博客文章:http://blog.csdn.net/lx_96/article/details/52126627
更多文章内容:http://blog.csdn.net/lx_96?viewmode=contents

您需要登录后才可以评论。登录 | 立即注册