1

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

8
  • Can you please post your complete config.xml? What you posted is probably not what is causing the error.
    – fmrng
    Oct 11, 2013 at 8:51
  • where is the dispatchEvent? Oct 11, 2013 at 8:53
  • @fmmg I have updated the post.
    – tony09uk
    Oct 11, 2013 at 9:03
  • Stupid question but... did you try to clear the cache? Simply delete everything under var/cache/. The error comes from this line: <class>training/observer</class>.
    – fmrng
    Oct 11, 2013 at 9:06
  • @FlorinelChris, sorry i don't understand your question, events and observers are really new to me
    – tony09uk
    Oct 11, 2013 at 9:06

2 Answers 2

3

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>
2
  • That's right, I hadn't seen that!
    – fmrng
    Oct 11, 2013 at 10:21
  • I only noticed it when you posted your answer :) Oct 11, 2013 at 10:21
2

The issue has been solve thanks to @ffmg for suggesting to change

<class>training/observer</class>

to

<class>Training_Animal_Model_Observer</class>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.