I have multi module setup with following directory structure.
-project --apps ----backend ----frontend ----webservice ----config ----common ------views ------models ----library --public --vendor
So far all works good as expected.
I now need to send emails from some actions of diffrent modules. I am using Swift Mailer plugin. It works fine for controller in frontend module, probabaly because it is default module but it wont work if i use it from controller of webservice module.
I have downlaoded the Swift mailer library and store it in vendor directory. Then crearted a file Mail.php in library directory taht has following code:
class Mail extends Component {
protected $_transport;
/**
* Applies a template to be used in the e-mail
*
* @param string $name
* @param array $params
*/
public function getTemplate($name, $params)
{
$parameters = array_merge(array(
'publicUrl' => $this->config->application->publicUrl,
), $params);
return $this->view->getRender('emailTemplates', $name, $parameters, function($view){
$view->setRenderLevel(View::LEVEL_LAYOUT);
});
return $view->getContent();
}
/**
* Sends e-mails via gmail based on predefined templates
*
* @param array $to
* @param string $subject
* @param string $name
* @param array $params
*/
public function send($to, $subject, $name, $params)
{
//Settings
$mailSettings = $this->config->mail;
echo $template = $this->getTemplate($name, $params);
//some code to send email
I have set Mail class in di aand use following code to send email :
$this->getDI()->getMail()->send( $admin_email, 'Beta list subscription', 'betajoin', array( 'email' => $email) );
When i call it from controller of webservice module it does not print template content but it works when i call it in frontend module.
What i guess is that getTemplate function does not load the view inside in webservice module.
Can I create a view in common/view/emailTemplates and render it inside the getTemplate function so I can keep all email template on common place?