Magento: Fatal error: calling the getModelInstance () member function for a non-object in the \ Mage.php application on line 432

I want to call a PHP file using ajax, where in this PHP I will place an order by calling ajax. But this causes an error when I use app / Mage.php from this file

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

then he says

Fatal error: calling the member function getModelInstance () on a non-object in app \ Mage.php on line 432

Can anyone help me ???

+7
source share
5 answers

Your proposed solution is not optimal. You have not initialized Magento, so the XML module is not loaded yet, and the factory template does not work.

Just use either:

 Mage::init(); // 1.5+ 

or

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

before using getModel.

+37
source

You must first initialize the Magento Framework first:

 /* 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()); 
+3
source

you need to initialize magento. the safest way to initialize it is to use an initializer before your actual model call

Mage :: Init ();

$ customer = Mage :: getModel ("client / client");

+1
source

I have the same error message. The decision was different. I forgot to give permission to the magento folder on Apache.

 chown -R apache:apache magento 
+1
source

I personally solved this using

 $customer = new Mage_Customer_Model_Customer(); 

instead of using

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

0
source

All Articles