php - Magento shell 命令 fatal error : Class "Mage" not found

标签 php magento magento-1.7 php-5.3

当我从/shell/目录中运行此命令时:

php -f regularPromos.php

为什么我会收到此错误?

PHP Fatal error: Class 'Mage' not found in /var/www/vhosts/yoohoo/httpdocs/shell/regularPromos.php on line 28

这是 regularPromos.php:

<?php

require_once 'abstract.php';

class Mage_Shell_RegularPromos extends Mage_Shell_Abstract
{     
    //Day of week to repeat promotion
    protected $day;

    //ID of promotion
    protected $promoID;

    //Rule process object
    protected $rule;


    public function Mage_Shell_RegularPromos($promoID, $day)
    {
        $this->day = $day;
        $this->promoID = $promoID;
        $this->rule = Mage::getModel('salesrule/rule');
    }


    public function run()
    {
        date_default_timezone_set('America/New_York');
        $nextWeek = date('Y-m-d', strtotime('next '. $this->day));
        $rule = $rule->load($this->promoID);
        $rule->setFromDate($nextWeek)
                ->setToDate($nextWeek)
                ->save();
    }
}

$shell = new Mage_Shell_RegularPromos(7, 'monday');
$shell->run();

?>

根据我能找到的关于这个问题的所有 SO 线程:

  • 我试过在编译器打开/关闭/清除/编译的情况下运行,但出现相同的错误消息

  • 我已通过管理面板清除缓存并手动删除 /var/cache/中的所有内容。

  • APC 不会出现在 phpinfo() 中,所以这应该不是问题 要么。

我可以很好地运行 compiler.php,所以我假设我在上面的 php 中犯了一个错误。

我正在运行 Magento 1.7 CE,PHP 5.3.3

最佳答案

也许如果你在脚本的开头添加这个:

require_once('./app/Mage.php');
Mage::app();

问候

关于php - Magento shell 命令 fatal error : Class "Mage" not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18318642/

相关文章:

php - magento 自定义 html 打印顺序

php - 禁用Cakephp的自动模型 "feature"

php - 组函数与 MAX 的使用无效

Magento - 从分层导航中检索当前系列中的最高产品价格

Magento:如何在某些其他JS文件之后自动添加JS文件?

magento - 运输方法在 magento 1.7 中不起作用

php - 如何爆炸()值并将其保存在变量中?

php - 无法让 ajax 发布工作

magento - 如何从前端 Controller 生成管理链接?

php - Magento : showing sub sub categories in same order as in admin backend tree structure