我在protected/views/directory_controller_name下有一个php文件,格式就是这样
<p>
<?php echo $model->title;?>
</p>
...
Run Code Online (Sandbox Code Playgroud)
我在控制器中使用经典方法显示文件:
$this->render('filename',array('model'=>$model));
Run Code Online (Sandbox Code Playgroud)
但是知道,我需要发送一个具有相同模板/布局的电子邮件,所以我想将文件的渲染存储在变量中
$ msgHTML = $ this-> renderInternal('_ items',array('model'=> $ model));
But it doesn't work!
Run Code Online (Sandbox Code Playgroud)
如何从文件中获取渲染视图并存储在变量中?可能吗?
我不想用:
$msgHTML = '<p>'.$model->title.'</p>'
...
Run Code Online (Sandbox Code Playgroud)
因为文件很长,我不想重复代码!!!
emi*_*mix 18
不要使用renderInternal方法,而是使用renderPartial.渲染内部是低级方法,不应在此类上下文中使用.要捕获输出,只需将$ return参数设置为true:
<?php $output = $this->renderPartial('_subView', $dataArray, true); ?>
Run Code Online (Sandbox Code Playgroud)
$msgHTML = $this->renderInternal('_items', array('model'=>$model), true);
Run Code Online (Sandbox Code Playgroud)
http://www.yiiframework.com/doc/api/1.1/CBaseController#renderInternal-detail
| 归档时间: |
|
| 查看次数: |
13572 次 |
| 最近记录: |