Forums / Developer / How to redirect from within a module?

How to redirect from within a module?

Author Message

Heiko Irrgang

Wednesday 16 February 2011 6:40:32 am

Hi, i want to redirect from within a own module to another module.

I have tried the usual way: header(sprintf('Location: %s', $url)); exit();

But ez stops with a message:

"Fatal error: eZ Publish did not finish its request. The execution of eZ Publish was abruptly ended,"

This comes from the exit(), but if i remove the exit, the redirect is ignored.

I found the RedirectOperators which allow redirection from a template and i checked the source: They do exactly the same. Why is it working from a template and not from a module? How can i redirect from a module?

Bertrand Dunogier

Wednesday 16 February 2011 7:28:51 am

In order to provide some feedback about fatal errors, eZ Publish uses a quite classical redirect based mechanism. If you exit() from the code without explaining eZ Publish it is on purpose and that the exit is expected, it will complain like this.

Use this code:

eZExecution::cleanExit();

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Heiko Irrgang

Thursday 17 February 2011 1:33:25 am

Thank you very much