1

I am creating a custom Module and Event Observer. I am using this tutorial as a base -tutorial.

My directory structure is just like in the tutorial

-app/
--code/
---local/
----[NameSpace]/
-----[Module]/
------Helper/
------Model/
------etc/
------sql/

In the Model folder I have a file named Observer.php

It contains:

class [NameSpace]_[Module]_Model_Observer
{
    public function receiveEvent(Varien_Event_Observer $observer){

     $order = $observer->getEvent()->getOrder();
     $result = Mage::getModel('[Namespace]_[Module]/example')
                    ->exampleFunction($order);
   return true;
}

I know that I have my observer and module set up correctly because if I put test code (write to a log) in the observer it runs fine.

I'm having trouble getting 'exampleFunction' to run. I get an error that says that it cannot include the correct file

Warning: include(): Failed opening 'Mage/[NameSpace]/[Module]/Model/Example.php' for inclusion

This is occuring in Varien/Autoload.php. The paths look fine except that it is sticking Mage on the front of the path. If it just said [NameSpace]/[Module]/Model/Example.php then it would work perfectly.

I do have a file named Example.php in the Model folder.

Does anyone know why it is putting 'Mage' on the front of the path and how I can remove it? I don't want to hack the actual autoload file, but I don't understand what's different about my code that it's not including this file correctly.


edit: Here is my config.xml file within the Module. I substituted the actual namespace and module names with the words NameSpace and Module

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <NameSpace_Module>
           <version>0.0.1</version>
    </NameSpace_Module>
</modules>

<global>

    <blocks> <!--Block folder--> 
        <Module> 
            <class>NameSpace_Module_Block</class> 
        </Module> 
    </blocks> 

    <blocks>
        <customer>
            <rewrite>
                <account_navigation>NameSpace_Module_Block_Account_Navigation</account_navigation>
            </rewrite>
        </customer>
    </blocks>

    <models>
        <Module>
            <class>NameSpace_Module_Model</class>
             <resourceModel>Module_mysql4</resourceModel>
        </Module>
        <Module_mysql4>
            <class>NameSpace_Module_Model_Mysql4</class>
            <entities>
                <missedorders>
                    <table>NameSpace_missedorders</table>
                </missedorders>
            </entities>
        </Module_mysql4>
    </models>
    <resources>
         <missedorders_setup>
            <setup>
                <module>NameSpace_Module</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </missedorders_setup>
        <missedorders_write>
            <connection><use>core_write</use></connection>
        </missedorders_write>
        <missedorders_read>
            <connection><use>core_read</use></connection>
        </missedorders_read>
    </resources>
    <events>
        <customer_address_save_after>
            <observers>
                <Module>
                <class>Module/observer</class>
                <method>receiveEvent</method>
                </Module>
            </observers>
        </customer_address_save_after>
        <sales_order_place_after>
            <observers>
                <Module>
                    <class>Module/observer</class>
                    <method>afterOrder</method>
                    <type>singleton</type>
                </Module >
            </observers>
        </sales_order_place_after>
        <controller_front_send_response_after>
            <observers>
                <Module>
                    <class>Module/observer</class>
                    <method>beforeFrontInit</method>
                    <type>singleton</type>
                </Module >
            </observers>
        </controller_front_send_response_after>
    </events>
    <helpers>
        <Module>
            <class>NameSpace_Module_Helper</class>
        </Module>
    </helpers>
</global>

<frontend>
    <routers>
        <Module>
            <use>standard</use>
            <args>
                <module>NameSpace_Module</module>
                <frontName>Module</frontName>
            </args>
        </Module>
        <Module>
            <use>standard</use>
            <args>
                <module>NameSpace_Module</module>
                <frontName>first-time-reset-process</frontName>
            </args>
        </Module>
        <Module>
            <use>standard</use>
            <args>
                <module>NameSpace_Module</module>
                <frontName>user-approval</frontName>
            </args>
        </Module>

    </routers>


    <layout>
        <updates>
            <Module module="NameSpace_Module">
                <file>namespace_Module.xml</file>
            </Module>
        </updates>
    </layout>  
</frontend>
<admin>
    <routers>
        <Module>
            <use>admin</use>
            <args>
                <module>NameSpace_Module</module>
                <frontName>Module</frontName>
            </args>
        </Module>
    </routers>
</admin>

<default>
    <web>
        <routers>
            <Module>
                <area>frontend</area>
                <class>NameSpace_Module_Controller_Router</class>
            </Module>
        </routers>
    </web>
</default>

  • can you post the content of the config.xml file of your module? – Marius Apr 7 '14 at 20:48
4

You need to replace

Mage::getModel('[Namespace]_[Module]/example')

with

Mage::getModel('[Module]/example')

The first part of the getModel parameter is the tag name you defined in config.xml right under the <models> tag.

2

When you use Mage::getModel('namespace/model') or Mage::getSingleton('namespace/model'), you have to define a node global/models/namespace/class with the content [NameSpace]_[Module]_Model.

If this class is missing, the classname resolving fallback on Mage:

app/code/core/Mage/Core/Model/Config.php:1253
\Mage_Core_Model_Config::getGroupedClassName
if (empty($className)) {
    $className = 'mage_'.$group.'_'.$groupType;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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