Problem with console command

Hello!

I tried to create a console command for cron, but I have a problem. I created the console command by guide http://www.yiiframework.com/doc/guide/1.1/en/topics.console and when cron executes, I have a message on my e-mail:




X-Powered-By: PHP/5.3.8

Content-type: text/html


No available commands.

Please define them under the following directory:

	/home/username/public_html/protected/commands

. I have the following cron command:


php /home/username/public_html/cron.php DeleteTmpFiles

. /cron.php


<?php

$yii = dirname(__FILE__) . '/../yii-1.1.9.r3527/framework/yii.php';

$config = dirname(__FILE__) . '/protected/config/cron.php';

//defined('YII_DEBUG') or define('YII_DEBUG', true);

require_once($yii);

Yii::createConsoleApplication($config)->run();

, /protected/config/cron.php


<?php

return array(

    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',

    'charset' => 'utf-8',

    'components' => array(

        'log' => array(

            'class' => 'CLogRouter',

            'routes' => array(

                array(

                    'class' => 'CFileLogRoute',

                    'logFile' => 'cron.log',

                    'levels' => 'error, warning',

                ),

                array(

                    'class' => 'CFileLogRoute',

                    'logFile' => 'cron_trace.log',

                    'levels' => 'trace',

                ),

            ),

        ),

    ),

    'import' => array(

        'application.components.*',

        'application.models.*',

    ),

    'name' => 'Cron',

    'params' => require(dirname(__FILE__) . '/params.php'),

    'preload' => array('log'),

);

, protected/commands/DeleteTmpFiles.php


<?php

class DeleteTmpFilesCommand extends CConsoleCommand

{

    public function run($args)

    {

        //

    }

}

. What am I doing wrong?

I solved a problem. I had an error in the filename of command…

Following this example, the information what exactly was wrong with the filename.

The filename of the commands file should have been like this:

protected/commands/DeleteTmpFilesCommand.php

MyBlaClassCommand.php ->> The word ‘Command’ has to be at the end of the filename.

You can use yiic because it’s already provides functionality that you wrote in ./cron.php

Steps are:

  1. Create new command in protected/commands directory (just like you did)

  2. Configure protected/config/console.php (optional, you used ./protected/config/cron.php for this)

  3. Install new cron job /absolute/path/to/protected/yiic DeleteTmpFiles // command name here is case-insensitive so this would work too: deletetmpfiles

Cheers