Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render view in yii console application

Tags:

rendering

yii

I have an email template in a view and I want to write a process that is ConsoleApplication that prepares emails to be send. Becouse it is ConsoleApplication I have no access to controller. Is it any way to render a view?

like image 230
liysd Avatar asked Nov 20 '10 13:11

liysd


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

It takes email template from views/email.

like image 157
Sam Dark Avatar answered Sep 28 '22 09:09

Sam Dark