[TYPO3-mvc] Run ControllerAction inside a Hook with 4.5

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed May 18 11:06:29 CEST 2011


Hey Steffen,

> So far, but how to add arguments for the action?
>
> e.g. I have blog comments, which I approve in the backend. When
> approved, an e-mail should be sent to the comment author. This should be
> done with the emailAction (since it is also used in some other contexts)
>
> My action is:
> emailAction(Tx_Ext_Domain_model_Comment)
>
> How do I tell the request to build a comment model object?

well, you could fake a _GET var, but that's not that nice though.
You could also outsource the email logic to a mailService and do the 
following:

$pluginConfiguration = array(
   'extensionName' => 'Foo',
   'pluginName' => 'Bar'
);
$bootstrap = t3lib_div::makeInstance('Tx_Extbase_Core_Bootstrap');
$bootstrap->initialize($pluginConfiguration);
# now you have a Extbase environment available
   // first grab the already preconfigured objectManager
$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
   // then grab the comment object from the repo
$repository = 
$objectManager->get('Tx_Foo_Domain_Repository_CommentRepository');
$comment = $repository->findByUid($row['uid']);
   // now trigger the notification service
$mailService = $objectManager->get('Tx_Foo_Domain_Service_MailService');
$mailService->notifyAuthorOnApproval($commment);


> My workaround is using fluid standalone:
...
> The odrawback here is that link.page does not seem to work in hook context:
> <f:link.page pageUid={myPid} absolute="1">Click here</f:link.page>
> -->
> <a href="http://www.example.com/mod.php?">Cick here</a>
>
> Is it possible to set FE context somehow?

I fear not, unless you temporarily change the TYPO3_MODE to 'FE'.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list