0

I've created an extension following a few tutorials which is meant to create an observer in order to add a layout handle.

in my logs I get the following on each page load

2017-01-25T14:56:04+00:00 ERR (3): Warning: include(Karl\CustomHandles.php): failed to open stream: No such file or directory  in C:\xampp\htdocs\raanthai2\lib\Varien\Autoload.php on line 94
2017-01-25T14:56:04+00:00 ERR (3): Warning: include(): Failed opening 'Karl\CustomHandless.php' for inclusion (include_path='C:\xampp\htdocs\raanthai2\app\code\local;C:\xampp\htdocs\raanthai2\app\code\community;C:\xampp\htdocs\raanthai2\app\code\core;C:\xampp\htdocs\raanthai2\lib;C:\xampp\php\PEAR')  in C:\xampp\htdocs\raanthai2\lib\Varien\Autoload.php on line 94
2017-01-25T14:56:07+00:00 ERR (3): Warning: include(Karl\CustomHandles.php): failed to open stream: No such file or directory  in C:\xampp\htdocs\raanthai2\lib\Varien\Autoload.php on line 94
2017-01-25T14:56:07+00:00 ERR (3): Warning: include(): Failed opening 'Karl\CustomHandless.php' for inclusion (include_path='C:\xampp\htdocs\raanthai2\app\code\local;C:\xampp\htdocs\raanthai2\app\code\community;C:\xampp\htdocs\raanthai2\app\code\core;C:\xampp\htdocs\raanthai2\lib;C:\xampp\php\PEAR')  in C:\xampp\htdocs\raanthai2\lib\Varien\Autoload.php on line 94

The path to the file seems to be affected by the class tag, in Karl\CustomHandles\etc\config.xml which is

<config>
<frontend>
    <events>
        <controller_action_layout_load_before>
            <observers>
                <customhandles>
                    <class>Karl_CustomHandles</class>
                    <method>addCustomHandles</method>
                </customhandles>
            </observers>
        </controller_action_layout_load_before>
    </events>

    <layout>
        <updates>
            <karl_customhandles module="Karl_CustomHandles">
                <file>customhandles.xml</file>
            </karl_customhandles>
        </updates>
    </layout>
</frontend>

1 Answer 1

1

Karl_CustomHandles is the name of the module and there should be no class called like that. If this is really the class name of your observer, first change it to Karl_CustomHandles_Model_Observer (it should be in the file Karl\CustomHandles\Model\Observer.php so that Magento can find it)

Then change the line in your config.xml to

                <class>Karl_CustomHandles_Model_Observer</class>

Or, even better, use a model alias:

<config>

    <frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <customhandles>
                        <class>customhandles/observer</class>
                        <method>addCustomHandles</method>
                    </customhandles>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </frontend>

    <global>
        <models>
            <customhandles>
                <class>Karl_CustomHandles_Model</class>
            </customhandles>
        </models>
    </global>

</config>

This is the recommended practice because other modules are now able to rewrite your observer model. But if this is just a custom module in your own project, the first solution with the class name should be good enough.

2
  • Does this mean it's necessary for the observers class name to match the path? This worked perfectly by the way. Jan 25, 2017 at 15:18
  • yes, all class names in Magento must match the file path. The only special case are controllers, where the controllers directory is not part of the class name. Jan 25, 2017 at 15:40

Your Answer

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

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