Name and Location are Key!

She’s going to bark at you if you don’t treat her with respect!  That’s why it’s key to provide the proper name and proper location  for any Magento files.  Any time you see the following in Magento, assume you got your wires crossed and start rechecking everything in the path:

 

( ! ) Fatal error: Call to a member function load() on a non-object in C:\xampp\htdocs\MagentoE\app\code\core\Mage\Core\Model\Abstract.php on line 225
Call Stack
# Time Memory Function Location
1 0.0006 145344 {main}( ) ..\index.php:0
2 0.0041 330992 Mage::run( ) ..\index.php:87
3 0.0150 983144 Mage_Core_Model_App->run( ) ..\Mage.php:683
4 1.7253 7152144 Mage_Core_Controller_Varien_Front->dispatch( ) ..\App.php:354
5 1.7378 7894792 Mage_Core_Controller_Varien_Router_Standard->match( ) ..\Front.php:176
6 1.7412 8120632 Mage_Core_Controller_Varien_Action->dispatch( ) ..\Standard.php:250
7 1.9243 11377120 MyModule_Complexworld_IndexController->indexAction( ) ..\Action.php:419
8 1.9247 11400536 Mage_Core_Model_Abstract->load( ) ..\IndexController.php:10

In this instance My Module Class’ model was in the correct location, but the name of the class for the model didn’t match the expected name Magento was hunting for:

<?php
class MyModuel_Complexworld_Model_Resource_Eavblogpost
extends Mage_Eav_Model_Entity_Abstract
{

}

Can you spot the problem in the code above? Yeah, a simple misspelling can cause a lot of grief in this system!  This hasn’t bit me yet, but I anticipate it will the more I trudge through this mammoth system.

EAV Resource Models

In Magento, resource model classes that rely on the EAV model are required to extend from Mage_Eav_Model_Entity_Abstract. 

If you instead extend from the standard model (Mage_Core_Model_Abstract) you’ll end up with an error such as this:

Resource is not set.
#0 Abstract.php(136): Mage::throwException('Resource is not...')
#1 Abstract.php(225): Mage_Core_Model_Abstract->_getResource()
#2 Abstract.php(225): Mage_Core_Model_Abstract->load(Object(MyModule_ComplexWorld_Model_Eavblogpost), 1, NULL)
#3 IndexController.php(10): Mage_Core_Model_Abstract->load(1)
#4 Action.php(419): MyModule_Complexworld_IndexController->indexAction()
#5 Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#6 Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#7 App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#8 Mage.php(683): Mage_Core_Model_App->run(Array)
#9 index.php(87): Mage::run('', 'store')
#10 {main}

Here is the code that generated this error:

<?php

class MyModule_Complexworld_Model_Resource_Eavblogpost

extends Mage_Core_Model_Abstract

//This should be Mage_Eav_Model_Entity_Abstract

{

}

Setting Developer Mode in Magento outputs Errors to screen

 

I updated the <VirtualHost> element in my Apache configuration file (apache/conf/extra/httpd-vhosts.conf) to include the environment variable “MAGE_IS_DEVELOPER_MODE”:

<VirtualHost *:80>
    documentroot "c:/xampp/htdocs/magento"
    servername magento.server.dev
    SetEnv MAGE_IS_DEVELOPER_MODE "1"
</VirtualHost>

By doing this, I can see any error that may have occurred during process of request.  This was done as a result of following the Magento For Developers: Part 5 – Magento Models and ORM Basics, which led me to the Wiki article Configure Magento error page, and a StackOverflow article discussing how to set up the environment variable.

As stated in the Wiki article, Magento handles outputs this way to eliminate the need of changing the index.php file for a production, staging or development server.