2016-07-18 2 views
1

일단 특정 URL을 입력하면 내 컨트롤러에서 모든 엔티티에 대한 crud를 재생성하고 싶습니다. 아래 예제는 데모 목적으로 하나의 엔티티 만 명령을 실행합니다. '/ reCrud'경로를 탐색하면 브라우저가 영원히 돌지 만 명령이 실행되지 않습니다. 꽤 재미있는 점은 같은 코드가 'cache : clear'를 실행할 때 잘 실행된다는 것입니다.symfony - 컨트롤러에서 엔티티에 대한 crud를 재생성하는 방법

<?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); 
    } 
} 

아마도 이것은 환경 구성 문제 일뿐입니다. 코드를 청크하고 컴퓨터에서 테스트하십시오. 작동하는지 여부를 알려주세요.

답변

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 
+0

고맙습니다. 또한 효과를 내기 전에 "--entity ="를 추가해야했지만 해결했습니다. 감사. 다음과 같이 anser를 편집 할 수 있습니다. doctrine : 생성 : crud --entity = AdminBundle : Klient --overwrite --no-debug --no-interact – DevWL

+0

@Fox sure, thanks – pavlovich

관련 문제