Display output from a Symfony task on a template

巧了我就是萌 提交于 2019-12-25 16:44:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!