Magento – observer failed to stream

configurationerrorevent-observerxml

I have been making and deleting custom modules to learn how magento works and I have now come across this error when I selected System | Permission | Roles | Administrator that error was fixed and now I have a new error that affect every admin page

Warning: include(Mage/Training/Model/Observer.php) [function.include]: failed to open stream: No such file or directory in /Users/tsimps/Sites/magentoDevTest/lib/Varien/Autoload.php on line 93

Looking at it I will guess that it is a misconfigured .xml file, the part it refering to (i believe) is

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Training_Animal>
        <version>0.1.0</version>
    </Training_Animal>
</modules>

<global>
    <models>
        <animal><!--Namespace name-->
            <class>Training_Animal_Model</class><!--File path to the model directory-->
            <resourceModel>training_animal_resource</resourceModel><!--maps to resource model node-->
        </animal>
        <training_animal_resource><!--resource model node-->
            <class>Training_Animal_Model_Mysql4</class><!--file path to the resource for that model-->
            <entities>
                <animal><table>training_animal_entity</table></animal>
            </entities>
        </training_animal_resource>
    </models>

    <resources>
        <training_animal_setup><!--the value that shows up in core_resource table & the folder name under the sql folder -->
            <setup>
                <module>Training_Animal</module><!--specifies the module I will be using-->
                <class>Mage_Core_Model_Resource_Setup</class><!--specifies the setup class to use (in this case it will be a simple entity)-->
            </setup>
        </training_animal_setup>
    </resources>

    <events>
        <animal>
            <observers>
                <training_animal_model_observer>
                    <type>singleton</type>
                    <class>Training_Animal_Model_Observer</class>
                    <method>controlleractionpredispatch</method>
                </training_animal_model_observer>
            </observers>
        </animal>
    </events>

    <helpers>
        <animal>
            <class>Training_Animal_Helper</class>
        </animal>
    </helpers>

    <blocks>
        <animal>
            <class>Training_Animal_Block</class>
        </animal>
    </blocks>

</global>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Training_Animal after="Mage_Adminhtml">Training_Animal_Adminhtml</Training_Animal>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

<adminhtml>
    <layout>
        <updates>
            <training>
                <file>training/animal.xml</file>
            </training>
        </updates>
    </layout>

    <events><!--a predispatch that logs every visited page to file that has been visited-->
        <controller_action_predispatch>
            <observers>
                <training_animal>
                    <type>model</type>
                    <class>training/observer</class>
                    <method>controllerActionPredispatch</method>
                </training_animal>
            </observers>
        </controller_action_predispatch>
    </events>
</adminhtml>

<frontend>
    <routers>
        <animal>
            <use>standard</use>
            <args>
                <module>Training_Animal</module>
                <frontName>animal</frontName>
            </args>
        </animal>
    </routers>
</frontend>
</config>

And the observer in question is

class Training_Animal_Model_Observer
{
public function controllerActionPredispatch(Varien_Event_Observer $observer)
{//used everytime an admin page is visited
    $user = Mage::getSingleton('admin/session')->getUser();
    if ( $user ) {
        $name = $user->getUsername();
    } else {
        $name = " NOT LOGGED IN ";
    }

    Mage::log($name . ' ' . Mage::app()->getRequest()->getPathInfo(), 
              Zend_Log::INFO, 'admin.log', TRUE);
}
}

I have reviewed this tutorial but cant see what i've done wrong

Best Answer

In your code you have the following

<class>training/observer</class>

But according to your set-up in the config.xml the namespace was animal and not training. It should have been as follows

<class>animal/observer</class>

Important section of config.xml

<animal><!--Namespace name-->
    <class>Training_Animal_Model</class><!--File path to the model directory-->
    <resourceModel>training_animal_resource</resourceModel><!--maps to resource model node-->
</animal>