【问题标题】:Symfony - How to regenerate crud for Entity from a controllerSymfony - 如何从控制器为实体重新生成 crud
【发布时间】: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


    【解决方案1】:

    它在旋转,因为它在下面等着你输入东西:

    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 =”,但你解决了它。谢谢。您可以按如下方式编辑您的分析器:教义:generate:crud --entity=AdminBundle:Klient --overwrite --no-debug --no-interaction
    猜你喜欢
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多