During normal process flow, a controller is run at the middle of the process (as shown in the Presentation). However, you may want to run code before and/or after a controller. Some possible cases are:

- you don’t know beforehand which node should be run : a node ID can be computed just before it’s run
- you want to encapsulate a controller, to control its conditions
- you want to capture the controller output

The basic idea is that a deferred is called before and after an existing controller is run, like this:

1 – $nodeRef = $deferred->reduce()
2 – $navigation->checkNode($node)
3 – $node->executeController()
4 – $deferred->failure() and exception handling
OR $deferred->success()
5 – theme output

Reduce

You can see here that $deferred->reduce() has the chance to run before authorization checks are done, therefore it can alter the environment, for example to allow access based on other criteria (IP, time, …).

Failure

In case of failure, $deferred->failure() is run after the controller but before exception handling, giving you the opportunity to alter the exception, add info, change the behavior, etc.

Success

If the controller runs ok, $deferred->success() can capture or alter the output data before it’s displayed by the theme.

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment