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)