Php Yii在命令中使用模型

Php Yii在命令中使用模型,php,yii,model,console,Php,Yii,Model,Console,我有一个Yii应用程序,我正在尝试向它添加一个命令 受保护的/commands/SendMessageCommand.php class SendMessageCommand extends CConsoleCommand { public function run($args) { $messages = Message::model()->findAll(array('type' => 'S', 'sent' => null, 'scheduled_

我有一个Yii应用程序,我正在尝试向它添加一个命令

受保护的/commands/SendMessageCommand.php

class SendMessageCommand extends CConsoleCommand {
    public function run($args) {
        $messages = Message::model()->findAll(array('type' => 'S', 'sent' => null, 'scheduled_for' => array('$ne' => null)));
        [....]
/protected/config/console.php

[....]
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'Phrizz Console',

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

    'import'=>array(
        'application.models.*',
        'application.forms.*',
        [....]
当我想跑的时候

$ yiic sendmessage
我要走了

PHP Fatal error:  Class 'Message' not found in /protected/commands/SendMessageCommand.php on line 7
如何在命令行脚本中访问模型


Yii 1.1.4

在Windows 7上出现了其他问题。解决方案:

class SendMessageCommand extends CConsoleCommand {
    public function run($args) {
        Yii::$enableIncludePath = false;
        $messages = Message::model()->findAll(array('type' => 'S', 'sent' => null, 'scheduled_for' => array('$ne' => null)));
        [....]

要澄清的是,Message是一个有效的模型,在整个应用程序中都使用它,在命令
run
方法中导入('application.models.Message'),以确保没有配置冲突,没有乐趣。我几分钟前就解决了。请看我的答案。