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);
}
}
おそらくこれは環境設定の問題です。コードをチャンクして、マシン上でテストしてください。それが動作するかどうか私に教えてください。
素晴らしい!ありがとうございました。私はまた働く前に "--entity ="を加えなければなりませんでしたが、あなたはそれを解決しました。ありがとう。以下のようにアンサーを編集できます: doctrine:generate:crud --entity = AdminBundle:Klient --overwrite --no-debug --no-interaction – DevWL
@Fox確かに、ありがとう – pavlovich