Rendering a view file in a console application

When someone want to send formatted HTML mails from a console application she/he will probably come across the problem of rendering view files.

The simlpest solution i could find was to use a behavior to bypass some web application specific problem (i used a widget to render the HTML templates with generated content).

Here is the behavior:

class CAViewRendererBehavior extends CBehavior
{
	public function getViewRenderer()
	{
		return NULL;
	}
	
	public function getTheme()
	{
		return NULL;
	}	
}

And the config:

return array(
	.
	.
	.
	'behaviors'=>array(
		'viewRenderer'=>'CAViewRendererBehavior',
	),
	'components'=>array(
		.
		.
		.
	);

The behavior implements the functions the widget checks before rendering by defaults. By returning NULL the widget skips rendering with a ViewRenderer and uses default directory (skipping the theme).

You can implement the two functions above, if you need to use a custom renderer, or a theme based template. Please note, that these functionalities are already implemented in Yii, so you can use them as a starting point.