2016-07-18 14 views
1

特定のURLを入力すると、コントローラからすべてのエンティティのためにcrudを再生成したいと思います。以下の例では、デモンストレーション目的で1つのエンティティのみのコマンドを実行しています。 '/ reCrud'のパスに移動すると、ブラウザは永遠に回転しますが、コマンドは決して実行されません。かなり興味深いのは、私が 'cache:clear'を実行したときに、同じコードがうまく動作するということです。Symfony - コントローラからEntityの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 ="を加えなければなりませんでしたが、あなたはそれを解決しました。ありがとう。以下のようにアンサーを編集できます: doctrine:generate:crud --entity = AdminBundle:Klient --overwrite --no-debug --no-interaction – DevWL

+0

@Fox確かに、ありがとう – pavlovich

関連する問題