简体   繁体   English

您如何在Zend Framework 2中呈现视图(用于HTML电子邮件)?

[英]How do you render a view (for HTML email purposes) in Zend Framework 2?

I've read several stack overflow posts on the subject, and they mention that in the controller you can use $this->getServiceLocator()->get('HttpRenderer') or something similar. 我已经阅读了几篇关于该主题的堆栈溢出文章,他们提到在控制器中可以使用$this->getServiceLocator()->get('HttpRenderer')或类似的东西。

However, I am not able to get the HttpRenderer service, as per the exception thrown belw. 但是,由于抛出异常,我无法获得HttpRenderer服务。 What am I doing wrong? 我究竟做错了什么?

======================================================================
   The application has thrown an exception!
======================================================================
 Zend\ServiceManager\Exception\ServiceNotFoundException
 Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for HttpRenderer
----------------------------------------------------------------------
/var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:529
#0 /var/opt/projects/MYAPP/web/module/Application/src/Application/Controller/CronController.php(53): Zend\ServiceManager\ServiceManager->get('HttpRenderer')
#1 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Application\Controller\CronController->mailAction()
#2 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#3 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#4 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#5 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Console\Request), Object(Zend\Console\Response))
#7 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#8 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#9 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 /var/opt/projects/MYAPP/web/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /var/opt/projects/MYAPP/web/public/index.php(30): Zend\Mvc\Application->run()
#12 {main}
======================================================================

I needed the following: 我需要以下内容:

$viewManager = $this->serviceLocator->get('ViewManager');

I could then call $viewManager->getViewRenderer()->render($viewModel) . 然后,我可以调用$viewManager->getViewRenderer()->render($viewModel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM