Reputation: 18850
I would like to regenerate crud for all my Entities from my controller once I enter specific url. The example below runs a command for only one Entity for demonstration purpose. When I navigate to the path '/reCrud', my browser will spin forever but the command never executes. What is quite interesting is that the same code, when I run 'cache:clear' instead, will run just fine.
<?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);
}
}
Perhaps this is only an environment configuration issue. Feel free to chunk that code and test it on your machine. Let me know if it works or not.
Upvotes: 1
Views: 965
Reputation: 1942
It spins because underneath it is waiting for you to enter stuff:
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]:
Solution:
Try adding -n
option which is:
-n, --no-interaction Do not ask any interactive question
So in the end your command would be something like this:
doctrine:generate:crud --entity=AdminBundle:Klient --overwrite --no-debug --no-interaction
Upvotes: 1