0

我正在开发命令行扩展的操作,仿照内置的cron.php 代码如下

扩展.php

require 'app/Mage.php';
$lowstockCollection = Mage::getResourceModel('reports/product_lowstock_collection')
->addAttributeToSelect('*')
->setStoreId($storeId)
->filterByIsQtyProductTypes()
->joinInventoryItem('qty')
->useManageStockFilter($storeId)
->useNotifyStockQtyFilter($storeId)
->setOrder('qty', Varien_Data_Collection::SORT_ORDER_ASC);

执行,出现如下信息“Call to a member function getResourceModelInstance() on a non-object”

对应的函数如下

应用程序/Mage.php

public static function getResourceModel($modelClass, $arguments = array())
{
    return self::getConfig()->getResourceModelInstance($modelClass, $arguments);
}

很明显,self::getConfig() -> getResourceModelInstance() 的问题

请问如何使用Command-Line Executive Mage::getResourceModel呢?

4

1 回答 1

0

cron.php 大部分代码拷贝进来,我就能用了,虽然我不明白他的动作原理 :P 程序大致如下

function xxx(){...}

require 'app/Mage.php';

if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

xxx;
于 2012-09-26T02:54:14.733 回答