【问题标题】:Cake 2 Shell: Undefined method success()Cake 2 Shell:未定义的方法成功()
【发布时间】:2013-10-30 10:08:26
【问题描述】:

我编写了一个使用 Cake-Shell 方法“success()”的 Cake-Shell,但这被声明为未定义。我在网上找不到任何描述该问题的线程。我可以看出,shell 几周前确实运行良好。

方法调用:

$this->success('success', array());

我通过

在我的 Windows-CLI 中调用 shell
cake ImportItems

它显然会通过它,但在应该触发 $this->success() 时会引发错误:

致命错误:调用未定义的方法 ImportItemsShell::success() in D:\xampp\htdocs\myCake\app\Console\Command\ImportItemsShell.php 第 29 行

这是我的 Shell 代码

require_once('libraries/Ini.php');
class ImportItemsShell extends AppShell {

/**
 * Main fn
 */
public function main() {
    $this->importItems();
}

/**
 * Get called by Cron
 */
protected function importItems() {
    $Shop= new Shop(SHOP_DB); 
    $items = Api::getItems(true);
    $mysql = MySQL::getInstance();
    $res = array();

    if(is_array($items) && ($items['status'] == Api::STATUS_OK)) {
        $Shop->importItems($items['values']);
        $this->success('success', $items['values']);
    } else {
        $this->error('invalid_item_response', array());
    }
}
}

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    错误是正确的,Cake 2.x 中没有Shell::success() 方法。与可以使用Shell::error()Shell::err() 将错误写入stderr 相比,使用Shell::out() 将“成功”消息简单地写入stdout

    也许只是您的错误报告设置发生了变化?

    更多信息请参见http://book.cakephp.org/2.0/en/console-and-shells.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多