Magento: Fatal error: Call to a member function ge

2019-01-27 21:51发布

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???

5条回答
Melony?
2楼-- · 2019-01-27 22:10

You should 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());
查看更多
▲ chillily
3楼-- · 2019-01-27 22:13

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

Mage::init();

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

查看更多
beautiful°
4楼-- · 2019-01-27 22:19

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

chown -R apache:apache magento
查看更多
女痞
5楼-- · 2019-01-27 22:21

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.

查看更多
手持菜刀,她持情操
6楼-- · 2019-01-27 22:29

I personally had solved it by using

$customer = new Mage_Customer_Model_Customer();

instead of using

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

查看更多
登录 后发表回答