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

itsazzad picture itsazzad · Aug 22, 2011 · Viewed 20.1k times · Source

I want to call a PHP file using ajax where in that PHP i will place order by the ajax call. But it throws error while i am using app/Mage.php from that file

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

then it says

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

Can anyone please help me???

Answer

Daniel Sloof picture Daniel Sloof · Aug 22, 2011

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

Simply use either:

Mage::init(); // 1.5+ 

or

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

before using getModel.