题
我在一个视图中的电子邮件模板,我想写一个过程,是ConsoleApplication,准备的邮件被发送。 Becouse它是ConsoleApplication我不得不控制器的访问权限。是它的任何方式来呈现视图?
解决方案
下面是我使用:
private function render($template, array $data = array()){
$path = Yii::getPathOfAlias('application.views.email').'/'.$template.'.php';
if(!file_exists($path)) throw new Exception('Template '.$path.' does not exist.');
return $this->renderFile($path, $data, true);
}
这需要电子邮件模板从的视图/电子邮件强>
其他提示
如果一切都失败了(如在我的情况下):
<?php
/**
* Renders a view file & returns result.
* @param string $_viewFile_ view file path
* @param array $_data_ optional data to be extracted as local view variables
* @param boolean $_return_ whether to return the rendering result instead of displaying it
* @return mixed the rendering result if required. Null otherwise.
*/
public function myRenderPartial($_viewFile_,$_data_=null,$_return_=true) {
if(is_array($_data_))
extract($_data_,EXTR_PREFIX_SAME,'data');
else
$data=$_data_;
if($_return_)
{
ob_start();
ob_implicit_flush(false);
require(YiiBase::getPathOfAlias("application.views").$_viewFile_.'.php');
return ob_get_clean();
}
else
{
require($_viewFile_);
}
}
?>
不隶属于 StackOverflow