问题
I am executing a task from an action in Symfony. I wish to capture the output from the task & display it to the (admin) user. Do I extract it from the dispatcher / log or somewhere else?
回答1:
This might not be the answer you're looking for, however, in a task you can log to a seperate file like so (within the execute function in the task class):
$fileLogger = new sfFileLogger($this->dispatcher,
array('file' =>$this->configuration->getRootDir().'/log/foobar.log'));
$this->dispatcher->connect('command.log', array($fileLogger, 'listenToLogEvent'));
And then in your task when you use:
$this->logSection('something', 'Log whatever message you want....', 1000);
It will automatically log to the custom log file.
Hope this helps. :-)
回答2:
Why not just perform the task within the action - and format the output in the template ? why are you running a separate task from an Action ? (i know this thread is old)
来源:https://stackoverflow.com/questions/6085939/display-output-from-a-symfony-task-on-a-template