2013-07-22 117 views
0

我想设置一个命令让我明确:高速缓存测试模式,然后做一个数据库,放置模式,添加方案,在测试模式下添加灯具。Symfony2命令改变环境

class BaseCommand extends \Symfony\Component\Console\Command\Command { 

//put your code here 

protected function configure() 
{ 
    $this 
      ->setName('mycommand:test') 
      ->setDescription('Launch test') 
    ; 

} 

protected function execute(InputInterface $input, OutputInterface $output) 
{ 
    $command_first_migration = $this->getApplication()->find('cache:clear'); 
    $arguments_first_migration = array(
     'command' => 'cache:clean', 
     '--env' => 'test' 
    ); 
    $input_first_migration = new ArrayInput($arguments_first_migration); 
    try { 

     $returnCode = $command_first_migration->run($input_first_migration, $output); 


    } catch (\Doctrine\DBAL\Migrations\MigrationException $ex) { 
     echo "MigrationExcepion !!!! "; 
    } 
} 

}

但我有这样的结果:

clearing the case for the dev environment with debug true 

如何通过在开发环境的考验吗?

谢谢

回答

1

您不能设置--env =测试由于内核和环境已经创建,当你运行PHP应用程序/控制台mycommand的:测试。

的唯一方法是,当你运行你的命令来指定ENV:

php app/console mycommand:test --env=test 
+0

谢谢。现在,当我使用教义:架构:创建我有这个错误:没有选定的数据库。 – Sworios

+1

你能为此打开一个新问题吗?不要忘记批准我的答案,如果它适合你:) – rpg600

+0

这是正确的答案,非常违反直觉,如果遵循SF2文档 – np87