[TYPO3-mvc] How to get to typoscipt ?
Franz Koch
typo3.RemoveForMessage at elements-net.de
Tue Jan 18 17:18:50 CET 2011
Hey,
> I'm experiencing another problem with my DI'd services, precisely my MailService. I'm trying to imiplement Bennys Mail Solution but with DI instead of extending another Class. (http://www.benny-vs-web.de/typo3/extbase-fluid-zum-rendern-von-e-mail-templates-verwenden/)
>
> Heres my current Plain Text rendering method:
> -------------------------------------
> protected function getPlainTextEmailView() {
> // create another instance of Fluid
> $view = t3lib_div::makeInstance('Tx_Fluid_View_TemplateView');
> // set the controller context
> $controllerContext = $this->controller->buildControllerContext();<- !! ERROR !! protected
> $controllerContext->setRequest( $this->controller->request );<- !! ERROR !! protected
> $view->setControllerContext( $controllerContext );
> // this is the default template path
> $templatePath = t3lib_extMgm::extPath( $this->extensionKey ) . 'Resources/Private/Templates/Email/';
> $templateFile = $templatePath.$templateName.'.txt';
> // set the e-mail template
> $view->setTemplatePathAndFilename( $templateFile );
> // and return the new Fluid instance
> return $view;
> }
> -------------------------------------
> $this->controller contains a reference to the calling controller. Not very nice, see my previous question.
> But... all the controller stuff is protected. How do I access these settings?
the issue here is not DI, but the fact that your MailService should be a
singleton, although it depends on plugin specific settings you don't
want to set/inject explicitly. At least the FLUID view needs a
controllerContext in order to create links etc - so you either have to
pass the controllerContext from your controllers to your "sendMail"
action or don't make it a singleton then.
I myself also have a mailService working similar to your example here -
I'm injecting the controllerContext manually after instantiation of the
service and then trigger the send process
($this->notificationService->setControllerContext($this->buildControllerContext())).
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list