Visualizations in the yii console application

I have an email template in a view, and I want to write a process, which is ConsoleApplication, which prepares emails for sending. Becouse is ConsoleApplication I do not have access to the controller. Is there any way to display the view?

+6
yii rendering
source share
2 answers

Here is what I use:

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); } 

Requires an email template from submissions / email .

+16
source share

If all else fails (as in my case):

 <?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_); } } ?> 
+1
source share

All Articles