【问题标题】:Yii Command Line Does Not Autoload ModelsYii 命令行不自动加载模型
【发布时间】:2013-03-25 13:14:32
【问题描述】:

我正在尝试使用 Yii 在命令行上运行命令。我的方法需要一个模型,但是当我运行命令时,Yii 说模型不存在,就好像它没有自动加载它一样。我的课很短很简单:

class ImportCommand extends CConsoleCommand {

    public function actionIndex() {

    }

    public function actionImport() {

        ini_set("display_errors", 1);
        set_time_limit(0);

        $cores = Core::model() -> findAll(array('limit' => 300000));

        foreach($cores as $core) {
            $core -> syncLocation();
        }


    }
}

错误信息如下所示:

./yiic import import
PHP Warning:  PHP Startup: Unable to load dynamic library '/opt/local/lib/php/extensions/no-debug-non-zts-20090626/php_xsl.dll' - dlopen(/opt/local/lib/php/extensions/no-debug-non-zts-20090626/php_xsl.dll, 9): image not found in Unknown on line 0
PHP Error[2]: include(Core.php): failed to open stream: No such file or directory
    in file /Users/dixond/Sites/nevada/yii/framework/YiiBase.php at line 421
#0 /Users/dixond/Sites/nevada/yii/framework/YiiBase.php(421): autoload()
#1 unknown(0): autoload()
#2 /Users/dixond/Sites/nevada/pub/webservice/protected/commands/ImportCommand.php(15): spl_autoload_call()
#3 unknown(0): ImportCommand->actionImport()
#4 /Users/dixond/Sites/nevada/yii/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs()
#5 /Users/dixond/Sites/nevada/yii/framework/console/CConsoleCommandRunner.php(67): ImportCommand->run()
#6 /Users/dixond/Sites/nevada/yii/framework/console/CConsoleApplication.php(91): CConsoleCommandRunner->run()
#7 /Users/dixond/Sites/nevada/yii/framework/base/CApplication.php(169): CConsoleApplication->processRequest()
#8 /Users/dixond/Sites/nevada/yii/framework/yiic.php(33): CConsoleApplication->run()
#9 /Users/dixond/Sites/nevada/pub/webservice/protected/yiic.php(7): require_once()
#10 /Users/dixond/Sites/nevada/pub/webservice/protected/yiic(4): require_once()

要让 Yii 自动加载模型,我需要做些什么特别的事情吗?

【问题讨论】:

  • 我认为你的路径是错误的,检查你的 urlrewrite 规则

标签: php command-line yii yii-cmodel


【解决方案1】:

yiic 命令通常使用与您的 Web 应用程序不同的配置文件。

在您的 config/console.phpimport 部分定义所需的路径,就像在您的 config/main.php 中一样。

【讨论】:

    【解决方案2】:
    Write this code in your config/console.php
    // autoloading model and component classes
        'import'=>array(
            'application.models.*',
            'application.components.*',
        ),
    

    更多详情http://www.yiiframework.com/doc/guide/1.1/en/topics.console

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      相关资源
      最近更新 更多