yiic command ... PHP Error[2]: include (Command.php): failed to open stream: No such file or directory in file ... YiiBase at line ...

Hi,

I’m writing this, because I was struggeling quite a long time with the following annoying error and want to share this since there might be other people torturing google for search results…

I created a command class Foo.php and put it under /protected/commands. Then, I checked via console and typed yiic… the command was displayed alongside with


./yiic


Yii command runner (based on Yii v1.1.<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />

Usage: ./yiic <command-name> [parameters...]


The following commands are available:

 - foo

 - message

 - migrate

 - shell

 - webapp


To see individual command help, use the following:

   ./yiic help <command-name>

But when I tried to run the command via ./yiic foo, it came up with


./yiic topupaccountsetting

PHP Error[2]: include(FooCommand.php): failed to open stream: No such file or directory

    in file /Users/tobi/Sites/yii/yii-1.1.8.r3324/framework/YiiBase.php at line 421



So what was the probleme here???

My Foo.php class looked like this:




class Foo extends CConsoleCommand

{

    

    public function run($args) {

        

        echo "Hello World"; 

        

    }

    

}



So what was the problem here?

I forgot to put "Command" behind the class name "Foo".

It must look like this




class FooCommand extends CConsoleCommand

{

    

    public function run($args) {

        

        echo "Hello World"; 

        

    }

    

}



That solved all the problems and the command is up and running.

The console.php config file is automatically used when running the command.

So running a command for a cronjob, you only need a ClassnameCommand extends CConsoleCommand in protected/commands which you can call via ./yiic classname

If it’s not working with your provider/webspace, maybe you should consider the php version running.

On Unix systems, you could force yii using PHP5 by changing the first row in protected/yiic to make it look like


#!/usr/bin/env php5

to have php5.

Hope I could help some helpless :)

Cheers Linus

Thank you very much for this post!

I’ve stuck in the same situation.