Symfony - 如何从控制器为实体重新生成 crud
Symfony - How to regenerate crud for Entity from a controller
一旦我输入特定 url,我想从我的控制器为我的所有实体重新生成 crud。下面的示例 运行s 是一个仅用于一个实体的命令,用于演示目的。当我导航到路径“/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
一旦我输入特定 url,我想从我的控制器为我的所有实体重新生成 crud。下面的示例 运行s 是一个仅用于一个实体的命令,用于演示目的。当我导航到路径“/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