If you use the extension yii-mail and want to use layouts do the following
Open YiiMailMessage file
add a public property called $layout
public $layout;
change the setBody method to
public function setBody($body = '', $contentType = null, $charset = null)
{
if ($this->view !== null) {
if (!is_array($body))
$body = array('body'=>$body);
if(isset(Yii::app()->controller))
$controller = Yii::app()->controller;
else
$controller = new CController('YiiMail');
$viewPath = $controller->getViewFile(Yii::app()->mail->viewPath.'.'.$this->view);
$body = $controller->renderInternal($viewPath, array_merge($body, array('mail'=>$this)), true);
if($this->layout!==null)
{
$layout=$controller->getLayoutFile($this->layout);
$body=$controller->renderInternal($layout,array('content'=>$body),true);
}
}
return $this->message->setBody($body, $contentType, $charset);
}
now use it like this
$message=new YiiMailMessage;
...
$message->layout='//mail/layout';
//points to the views folder / mail / layout.php
//or
$message->layout='test';
//will point to the layouts folder / test.php
[size="3"]note:[/size] it will use the same approach a controller does to render a layout
so you can use paths like ‘test’ that will point to the alias application.views.layouts.test
or ‘//mail/test’ that will point the the alias application.views.mail.test
the same applies for the view, you can set your views like you do in when rendering a view, like //test/myView
attached is the modified file
Hope this helps