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);
}
}
아마도 이것은 환경 구성 문제 일뿐입니다. 코드를 청크하고 컴퓨터에서 테스트하십시오. 작동하는지 여부를 알려주세요.
고맙습니다. 또한 효과를 내기 전에 "--entity ="를 추가해야했지만 해결했습니다. 감사. 다음과 같이 anser를 편집 할 수 있습니다. doctrine : 생성 : crud --entity = AdminBundle : Klient --overwrite --no-debug --no-interact – DevWL
@Fox sure, thanks – pavlovich