【问题标题】:How to save doctrine database schema in a Symfony controller?如何在 Symfony 控制器中保存学说数据库模式?
【发布时间】:2014-06-02 12:49:51
【问题描述】:

我正在使用 Symfony 2.3 和 Doctrine 2,我需要用户将 Doctrine 数据库的模式保存到文件 (*.sql) 中。我需要将其转换为操作方法,然后将文件发送给用户

【问题讨论】:

    标签: database symfony controller doctrine actionmethod


    【解决方案1】:

    您需要执行以下命令:

    .app/console doctrine:schema:create --dump-sql >schema.sql
    

    这是如何从Controller 运行Command 的答案:How can I run symfony 2 run command from controller

    【讨论】:

      【解决方案2】:

      只是为了让您开始,这应该在概念上起作用。我没能运行它,所以我认为它可能需要您对它进行一些调整。

      <?php
      use Symfony\Component\Console\Input\ArrayInput;
      use Symfony\Component\Console\Output\NullOutput;
      use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
      
      // your controller
      
      public function myAction()
      {
          $command = new CreateSchemaDoctrineCommand();
          $command->setContainer($this->container);
          $input = new ArrayInput(array('--dump-sql' => true));
          $output = new NullOutput();
          $schema = $command->run($input, $output); //This is your schema
      
          // Write it to a file if you want
          file_put_contents('path/to/schema.sql', $schema);
      }
      

      参考资料:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        • 1970-01-01
        • 2018-08-15
        • 1970-01-01
        • 1970-01-01
        • 2019-07-30
        • 2011-04-20
        相关资源
        最近更新 更多