我正在使用zend framework 2.1.5,我想发送带有自定义电子邮件模板的电子邮件。这是我的代码
$view = $this->getServiceLocator()->get('Zend\View\Renderer\RendererInterface');
$viewModel = new \Zend\View\Model\ViewModel();
$template = 'forgot_password.phtml';
$viewModel->setTemplate($template)
->setVariables(array('data' => $data));
$content = $view->render($viewModel);
收到错误Zend\View\Renderer\PhpRenderer::render: Unable to render template "forgot_password.phtml"; resolver could not resolve to a file
答案 0 :(得分:2)
注意:将解析器设置为您的视图,如下所示
$view = $this->getServiceLocator()->get('Zend\View\Renderer\RendererInterface');
$resolver = new \Zend\View\Resolver\TemplatePathStack();
$resolver->setPaths(array(
'mailTemplate' => __DIR__ . 'TEMPLATE PATH'
));
$view->setResolver($resolver);
$viewModel = new \Zend\View\Model\ViewModel();
$template = 'forgot_password.phtml';
$viewModel->setTemplate($template)
->setVariables(array('data' => $data));
$content = $view->render($viewModel);
这可能会对你有帮助。