【发布时间】:2018-08-06 13:55:11
【问题描述】:
我在 Symfony 中创建了一个清除缓存并从 web 目录中删除所有翻译的命令。命令名称为:
$this->setName('dump-translations')
并且命令正在完美地从控制台运行,但是当我从控制器调用它时,我得到了响应:
Command "dump-translations" is not defined.
我想我错过了一些步骤,但找不到答案。 代码如下:
namespace Pi\Bundle\WhiteLabelBundle\Controller;
use Pi\Bundle\WhiteLabelBundle\Command\DumpTranslationsCommand;
use Pi\Bundle\WhiteLabelBundle\YmlReader\YmlReader;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
class DefaultController extends Controller
{
public function indexAction()
{
(new YmlReader())->readYmlFile();
echo $this->sendSpool();
return $this->render('Pi\WhiteLabelBundle:Default:index.html.twig');
}
public function sendSpool()
{
$application = new Application($this->get('kernel'));
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'dump-translations'
));
$output = new BufferedOutput();
$application->run($input, $output);
$content = $output->fetch();
return new Response($content);
}
}
【问题讨论】: