Yii::app() accessible while active records are not…

Hi everyone,

I’ve been using console commands for some time now from cron jobs mainly. They work just fine.

I’ve been trying for a specific project to catch incoming emails and process them upon certain conditions. Catching and filtering are done by cPanel, so I’m just using the ‘Pipe to a program’ action, like this:

|/path/to/protected/yiic processIncomingEmail

My issue: It seems that I can access only Yii::app() and nothing else “Yii” (ie I can’t access models or class constants).

Fortunately, I’ve implemented workarounds, but I’d like to know whether I’m doing something wrong or it’s by design, or even Yii-independent.

For instance:


class ProcessIncomingEmailCommand extends CConsoleCommand


    public function run($args)


        // The following works

        $connection = Yii::app()->db;

        $sql = // standard sql INSERT command;

        $command = $connection->createCommand($sql);


        // The following doesn't work when in pipe mode, but works in cron mode

        $model = new Model;

        $model->attribute = 145;


        // This works

        $sql = 'UPDATE Model SET attribute = ' . Yii::app()->params['someConstant'] . ' WHERE id = 1234';

        $command = $connection->createCommand($sql);


        // This doesn't work when in pipe mode, but works in cron mode

        $sql = 'UPDATE Model SET attribute = ' . Model::SOME_CONSTANT . ' WHERE id = 1234';

        $command = $connection->createCommand($sql);


        // Also Model::model()->find() etc. don't work in pipe mode


} ?>

Does it ring a bell to anyone?

Thanks in advance!


Anyone please, is there something wrong or is it by PHP / Yii / Linux / Apache / SendMail design?

I’ve forgotten to tell that when I say it doesn’t work, it fails silently in fact.

Meaning any code before the culprit code line is run, and the application is halted.

application.log doesn’t show any errors. Maybe I should enable debug mode and retry…

Well in fact I had ran non working tests in test env. so debug was on, and I checked application.log: no errors for my tests…

So I re-activated the non-working code lines, but using the production’s console command and… it worked! I’m gonna stop digging more, but leaving the thread in any case someone experiences same problem.

hmm ok I’m back again. Could it be that debug mode = on in my test env. was the cause of the problem?

I’m looking at this issue: https://github.com/yiisoft/yii/issues/497

I’m using 1.1.10