0

我正在使用 zend 框架 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

4

1 回答 1

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

这可能会对您有所帮助。

于 2013-10-14T09:25:06.353 回答