【问题标题】:Magento: Fatal error: Call to a member function getModelInstance() on a non-object in app\Mage.php on line 432Magento:致命错误:在第 432 行的 app\Mage.php 中的非对象上调用成员函数 getModelInstance()
【发布时间】:2011-11-01 00:03:30
【问题描述】:

我想使用 ajax 调用 PHP 文件,在该 PHP 中我将通过 ajax 调用来下订单。但是当我使用该文件中的 app/Mage.php 时它会引发错误

require_once '../../../../../../../../../../app/Mage.php';    
$customer = Mage::getModel('customer/customer');

然后它说

致命错误:调用成员函数 getModelInstance() 第 432 行 app\Mage.php 中的非对象

谁能帮帮我???

【问题讨论】:

  • 我已经通过使用 $customer = new Mage_Customer_Model_Customer();而不是使用 $customer = Mage::getModel('customer/customer');

标签: magento fatal-error mage


【解决方案1】:

您提出的解决方案不是最优的。您尚未初始化 Magento,因此尚未加载模块 XML,并且工厂模式不起作用。

只需使用任一:

Mage::init(); // 1.5+ 

Mage::app(); // (pretty much anything) below 1.5

在使用 getModel 之前。

【讨论】:

  • 它向我显示了这个错误“Mage 注册表项“控制器”已经存在”
  • 谢谢丹尼尔斯洛夫。我为这个错误做了很多努力。 +11111111
  • 谢谢丹尼尔,帮助了。
  • 8 年后,您仍在帮助人们解决这个问题...+1
【解决方案2】:

你应该先初始化 Magento 框架:

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::init($mageRunCode, $mageRunType, array());

【讨论】:

  • 似乎Mage::init($mageRunCode, $mageRunType); 更合适,但是+1! (但请注意,我使用的是 Mage EE 1.12。不同版本可能会有所不同:)谢谢,解决了我的错误。
【解决方案3】:

你需要初始化magento。最安全的初始化方法是在实际调用模型之前使用初始化器

法师::init();

$customer = Mage::getModel('customer/customer');

【讨论】:

    【解决方案4】:

    我收到了同样的错误信息。解决方案不同。我忘记将 magento 文件夹的权限授予 Apache。

    chown -R apache:apache magento
    

    【讨论】:

      【解决方案5】:

      我个人已经通过使用解决了它

      $customer = new Mage_Customer_Model_Customer();
      

      而不是使用

      $customer = Mage::getModel('customer/customer');
      

      【讨论】:

        猜你喜欢
        • 2014-09-30
        • 2015-07-27
        • 1970-01-01
        • 1970-01-01
        • 2010-12-20
        • 2015-06-16
        • 2016-02-02
        • 2014-05-06
        • 1970-01-01
        相关资源
        最近更新 更多