douxiong5438
2014-01-27 08:58
浏览 177
已采纳

在symfony中执行自定义控制台命令时出现致命错误

I'm trying to create a custom console command for my project so i thought I'll first try it out with the example given in the symfony site, I have provided the steps it took to reach this far,

Step 1: Added  "symfony/console": "2.3.*@dev", to composer.json.
Step 2: Updated composer.

The code written for the command is given below

class Sendgcmfuctions extends ContainerAwareCommand {
protected function configure()
{
    $this
        ->setName('demo:greet')
        ->setDescription('Greet someone')
        ->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?')
        ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
    ;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
    $name = $input->getArgument('name');
    if ($name) {
        $text = 'Hello '.$name;
    } else {
        $text = 'Hello';
    }

    if ($input->getOption('yell')) {
        $text = strtoupper($text);
    }

    $output->writeln($text);
}
}

On running "php app/console demo:greet" the following error is produced

PHP Fatal error:  Class 'Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand' not found in /var/www/MobpazAdmin/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/Proxy/QueryRegionCacheDoctrineCommand.php on line 29

The "Sendgcmfuctions" is inside a Command folder inside my bundle. Please tell me the mistake commited while doing this

图片转代码服务由CSDN问答提供 功能建议

我正在尝试为我的项目创建一个自定义控制台命令,所以我想我会先尝试一下 在symfony网站上给出的例子中,我提供了到达目前为止所采取的步骤,

 步骤1:添加了“symfony / console”:“2.3.*@dev  “,to composer.json。
第2步:更新了作曲家。
   
 
 

为命令编写的代码如下所示

  class Sendgcmfuctions扩展ContainerAwareCommand {
protected function configure()
 {
 $ this this n> setName('demo:greet')
  - > setDescription('Greet someone')
  -  > addArgument('name',InputArgument :: OPTIONAL,'你想问候谁?')
  - > addOption('yell',null,InputOption :: VALUE_NONE,'如果设置,任务将大喊大叫 大写字母')
; 
} 
 
保护函数execute(InputInterface $ input,OutputInterface $ output)
 {
 $ name = $ input-> getArgument('name'); 
 if($ 姓名){
 $ text ='地狱 o'。$ name; 
} else {
 $ text ='Hello'; 
} 
 
 if($ input-> getOption('yell')){
 $ text = strtoupper($ 文本); 
} 
 
 $ output-> writeln($ text); 
} 
} 
   
 
 

运行“php app / 控制台演示:问候“生成以下错误

  PHP致命错误:/ var /中找不到类'Doctrine \ ORM \ Tools \ Console \ Command \ ClearCache \ QueryRegionCommand'  www / MobpazAdmin / vendor / doctrine / doctrine-bundle / Doctrine / Bundle / DoctrineBundle / Command / Proxy / QueryRegionCacheDoctrineCommand.php第29行
   
 
 

“Sendgcmfuctions”是 在我的包内的Command文件夹中。 请告诉我这样做时犯下的错误

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dtsc1684 2014-01-27 10:57
    已采纳

    it seems to be an issue of doctrine's latest bundle. try use another stable version.

    "doctrine/doctrine-bundle": "1.2.0" works for us

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanmei1350 2014-01-27 09:01

    Try to use next require in composer.json:

    "symfony/console": "~2.3"
    

    It's probably an vendor error. Try to use later stable version

    评论
    解决 无用
    打赏 举报
  • duanhuren5581 2014-01-28 05:22

    I did as Max suggested and the installation went smoothly, the exception

    [InvalidArgumentException]
    There are no commands defined in the "demo" namespace.

    was due to a naming problem had to add a suffix of to the class name as Command

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题