I have a controller that, among other things, sends emails. I need to echo a message to the user before the email sending starts (otherwise it looks like the screen is stuck).
So, how do I echo a message which is set in the start of a controller, before I reach the end of the controller, or, should I think in another direction all together?
views:
234answers:
3
A:
Try maybe:
<?php
//...
public function someAction()
{
echo "Something";
ob_flush();flush();
}
This forum post discusses your issue. They suggest:
<?php
$frontController = Zend_Controller_Front::getInstance();
$frontController->setParam('disableOutputBuffering', true);
And then performing the ob_flush();flush();
technique.
dcousineau
2009-09-23 15:33:38
I need the layout to be there too.
Itay Moav
2009-09-23 15:39:08
In that case you could do some kind of AJAX request when your view is loaded, because, the Layout is rendered after the controller Action has been executed, not during.
Chris
2009-09-24 03:26:49
Thought so...Thanks!
Itay Moav
2009-09-29 02:29:45
A:
You could try using a shutdown function to send the email. If you also flush the output buffer this will make sure the user gets to see the rendered page first. In your code call:
register_shutdown_function('send_email', $params);
And then have a function that looks like:
function send_email($params) {
ob_flush();flush();
// Send your email here
}
Neel
2009-09-28 18:57:26
+1
A:
For the mail part of the question.
Depending on the timing - how soon after the request the message needs to be sent - another possiblity would be to create a message queue (maybe a db table), write a record to that table, and then run a cron process that consumes the queue, sending any unsent messages, marking them as sent, etc.
David Weinraub
2009-09-30 03:26:18