Creating A Cron Based Console Application

I am having trouble debugging the console application, there seems to be some differences between some examples and the wiki

entries for console apps.

One point of confusion is whether to use "yiic test" or "cron.php test"

I created a simple command file extending CConsoleCommand



class TestCommand extends CConsoleCommand {


    public function run($args) {

        // here we are doing what we need to do

	// create a contact record

	$c = new Contact;

	$c->last_name = 'Harter';

	$c->first_name = 'Bryan';

	$c->contact_type = 2; 





cron.php script file:

#!/usr/bin/env php


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

// including Yii



// we'll use a separate config file



// creating and running console application



Cronjob file cron.php:


return array(

    // This path may be different. You can probably get it from `config/main.php`.








    // We'll log cron messages to the separate files








                    'levels'=>'error, warning',









        // DB connection


		'class' => 'CDbConnection',

		'connectionString' => 'mysql:host=localhost;dbname=***',

		'emulatePrepare' => true,

		'username' => '*******',

		'password' => '*******',

		'charset' => 'utf8',


    ), //components



I call the script from the protected folder ./cron.php test

I receive output of PHP Error[2]: include (EActiveRecordRelationBehavior.php): filed to open stream: No such file or directory

in file /usr/share/nginx/www/myapp/framework/YiiBase.php at line 421.

Seems to be an autoload problem from YiiBase.php

It seemed to find the model and other components, but I am uncertain what the problem is.

Anyone have any ideas what I am doing wrong or need to change?


in your contact model behaviors method you have to write full path to your EActiveRecordRelationBehavior class,


'class' => 'ext.behaviors.EActiveRecordRelationBehavior'


Thank you MBI I will make that change and continue testing.

It made a difference but still errored out.

‘CException’ with message ‘Alias “ext.behaviors.EActiveRecordRelationBehavior” is invalid. Make sure it points to an existing PHP file and file is readable.’ in /usr/share…YiiBase.php:316

My EActiveRecordRelationBehavior file should not be anything out of the ordinary…I’ve been using the contact model

as a standard model for several months.

ext.behaviours…would imply it is an extension of the AR behaviors…but it is plain vanilla yii…

I am however using awegen for my generator in place of standard gii.

I had to change the path to ‘ext.awegen.components…’

Thanks so much for the help!!

Is it possible to call a controller method ?

I was successful in doing a simple data insert using Active Record methods.

Normally the controller renders a view. Do I need to create a new method that just

does what I need it to do?