2014-06-06 32 views
0

首先,我想要做的是學習用的文檔 http://symfony.com/doc/current/cookbook/console/console_command.html控制檯命令:找到該文件,但該類不在其中,類名或命名空間可能有拼寫錯誤。

我想複製正是被文檔

這上完成創建自己的控制檯命令是我一直走到這一步,

<? 
// src/Gabriel/LiveLoginBundle/Command/GreetCommand.php 
namespace Gabriel\LiveLoginBundle\Command; 

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Output\OutputInterface; 

class GreetCommand 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); 
    } 
} 

但由於某些原因,它拋出這個錯誤,它似乎無法找到類

找到該文件但該類不在其中,類名或 命名空間可能有錯字。

PS:已經嘗試刪除緩存

+2

嘗試使用正確的<?php;) – ElPoney

+0

冬青的廢話,它的作品 – user3531149

+1

發佈這個答案 – user3531149

回答

0

默認情況下你的PHP配置(php.ini中)不允許你使用簡短的開幕標籤

<? ?> 
<?= ?> 

所以,你必須添加在php.ini以下指令

short_open_tag=On 

最好的辦法是由F取代你的短標籤<?無論如何<?php無處不在

相關問題