Command line Symfony-如何从控制器为实体重新生成crud

Command line Symfony-如何从控制器为实体重新生成crud,command-line,controller,crud,symfony,Command Line,Controller,Crud,Symfony,一旦我输入特定的url,我想从我的控制器为我的所有实体重新生成crud。下面的示例仅为一个实体运行命令以进行演示。当我导航到路径“/reCrud”时,我的浏览器将永远旋转,但命令永远不会执行。有趣的是,当我运行“cache:clear”时,同样的代码运行得很好 <?php namespace AdminBundle\Controller; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\

一旦我输入特定的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);
    }
}

它会旋转,因为它下面正等着你输入内容:

Welcome to the Doctrine2 CRUD generator  



This command helps you generate CRUD controllers and templates.

First, give the name of the existing entity for which you want to generate a CRUD
(use the shortcut notation like AcmeBlogBundle:Post)

The Entity shortcut name [AdminBundle:Klient]: 

解决方案:

尝试添加
-n
选项,该选项为:

-n, --no-interaction             Do not ask any interactive question
所以最后你的命令是这样的:

doctrine:generate:crud --entity=AdminBundle:Klient --overwrite --no-debug --no-interaction

伟大的非常感谢。我还必须添加“-entity=”才能生效,但您解决了它。谢谢您可以按如下方式编辑您的anser:原则:生成:crud--entity=AdminBundle:Klient--overwrite--no debug--no interaction