【发布时间】:2016-07-18 04:12:49
【问题描述】:
一旦我输入特定的 url,我想从我的控制器为我的所有实体重新生成 crud。下面的示例仅为一个实体运行命令以进行演示。当我导航到路径“/reCrud”时,我的浏览器将永远旋转,但该命令永远不会执行。有趣的是,同样的代码,当我运行 'cache:clear' 时,会运行得很好。
<?php
namespace AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class CrudController extends Controller
{
/**
* @Route("/reCrud")
*/
public function reCrudAction()
{
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new StringInput('doctrine:generate:crud AdminBundle:Klient --overwrite --no-debug');
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();
// return new Response(""), if you used NullOutput()
return new Response($content);
}
}
也许这只是一个环境配置问题。随意分块该代码并在您的机器上进行测试。让我知道它是否有效。
【问题讨论】:
标签: command-line controller crud symfony