9

I install magento 1.9.0.0 and copy to my xampp htdocts when I run localhost/magento this error shows,i've done the solutions but it didn't work.

Fatal error: Call to a member function getModelInstance() on a non-object in    
 /Applications/XAMPP/xamppfiles/htdocs/magento/app/Mage.php on line 463

Here is the code script:

public static function getModel($modelClass = '', $arguments = array())
  {
    return self::getConfig()->getModelInstance($modelClass, $arguments);
  }
Ravi Dhoriya ツ
  • 4,435
  • 8
  • 37
  • 48
user3728443
  • 93
  • 1
  • 1
  • 3

5 Answers5

24

The problem is related with some write permissions. Set write permissions to the following folders app/etc, var and media.

cd /xampp-folde/htdocs/magento
chmod -R 777 app/etc
chmod -R 777 var
chmod -R 777 media
BenRoe
  • 1,714
  • 17
  • 27
  • 2
    I think the magento team suppose to throw a reasonable exception when a directory is not writable instead of the referenced error. – elf1984 Oct 10 '14 at 08:00
  • There are many exceptions that the magento team could have handled better –  Aug 22 '16 at 00:16
12

In case you are getting this error while trying to access Magento outside in a script

The solution given here should be considered first before playing with permissions.

Mage::init(); // 1.5+

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

Community
  • 1
  • 1
Imran Zahoor
  • 2,521
  • 1
  • 28
  • 38
5

If you are running a custom script you might have forgotten to set the current store.

Examples:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::app()->setCurrentStore('my_store_id');

If you don't set a store then calls to Mage::getModel will result in the mentioned error.

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
4

What is really causing your problem is that your Magento installation directory and files do not have correct permissions. XAMPP runs Apache as a user called daemon by default. If you don't want that, you can change it in httpd.conf. This solves the problem without doing anything else.

But you can just change the owner of the files, too. You should never grant everybody access to your files by just telling chmod 777. 777'ing your files is a major security issue if you ever move those files to a production environment.

Instead doing chmod 777, change the owner of the directory using chown. Go to your Magento directory (in your case cd /Applications/XAMPP/xamppfiles/htdocs/magento/) and use this command to recursively change the owner of all files and directories to daemon:

sudo chmod -R daemon .

tukkaj
  • 596
  • 1
  • 6
  • 16
4

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());
Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
Ipsita Rout
  • 4,945
  • 4
  • 36
  • 40