Database 如何在Symfony控制器中保存条令数据库模式?
我正在使用Symfony 2.3和条令2,我需要用户将条令数据库的模式保存到文件(*.sql)中。我需要将其转换为一个操作方法,然后将文件发送给用户您需要执行以下命令:Database 如何在Symfony控制器中保存条令数据库模式?,database,symfony,controller,doctrine,actionmethod,Database,Symfony,Controller,Doctrine,Actionmethod,我正在使用Symfony 2.3和条令2,我需要用户将条令数据库的模式保存到文件(*.sql)中。我需要将其转换为一个操作方法,然后将文件发送给用户您需要执行以下命令: .app/console doctrine:schema:create --dump-sql >schema.sql 下面是如何从Controller运行命令的答案:为了让您开始,这在概念上应该是可行的。我没有运行它,所以我想它可能需要您的一点调整 <?php use Symfony\Component\Conso
.app/console doctrine:schema:create --dump-sql >schema.sql
下面是如何从
Controller
运行命令的答案:为了让您开始,这在概念上应该是可行的。我没有运行它,所以我想它可能需要您的一点调整
<?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);
}