douqiao7958 2015-03-28 00:10
浏览 222

Symfony:致命错误:在app / console中找不到类

I'm trying to get commands from command line to work using symfony. I have the following folder structure:

  • app console
  • src
    • Source
      • Commands twitterCommand.php

Now in my console file I have the following code:

#!/usr/bin/env php

require_once '/../vendor/autoload.php';

use Source\Commands\TwitterCommand;
use Symfony\Component\Console\Application;
use Endroid\Twitter\Twitter;

//API Keys

$client = new Twitter($consumerKey, $consumerSecret, $accessToken,   $accessTokenSecret);

$application = new Application();
$application->add(new TwitterCommand($client));

And then in my TwitterCommand.php i have the following:


namespace Source\Commands;

use Twitter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;

class TwitterCommand extends Command
private $client;

public function __construct(Twitter $client)
    $this->client = $client;

protected function configure()
        ->setDescription('Show the tweets')

protected function execute(InputInterface $input, OutputInterface $output)

    // Retrieve the user's timeline
    $tweets = $twitter->getTimeline(array(
        'count' => 5

    // Or retrieve the timeline using the generic query method
    $response = $twitter->query('statuses/user_timeline', 'GET', 'json', $parameters);
    $tweets = json_decode($response->getContent());


The problem is I'm getting a 'Fatal error: Class 'Source\Commands\TwitterCommand' not found in C:...' and the error is sent in this line:

$application->add(new TwitterCommand($client));

Any idea on what am I doing wrong?

  • 写回答

1条回答 默认 最新

  • doue1925 2015-03-28 09:52

    If you want your class to be autoloaded you have to fallow PSR-0 standard. In the composer.json of your project you have probably defined something like that:

    "autoload": {
        "psr-0": { "": "src/" }

    Your class file path should be src/Source/Commands/TwitterCommand.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥20 双系统开机引导中windows系统消失问题?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方
  • ¥15 关于生产日期批次退货退款,库存回退的问题
  • ¥15 手机应用的时间可以修改吗
  • ¥15 docker 运行OPEN-webui异常
  • ¥15 麒麟系统如何删除光盘刻录痕迹
  • ¥15 recipe通过gem协议传的是什么
  • ¥15 TS2307: Cannot find module 'cc'.
  • ¥15 100小时学会sap 书上pp章节5.22,标准成本计算逻辑?