2

I always get following error when calling $this->loadLayout() inside postAction() of my IndexController:

Fatal error: Class 'Mage_Package_MyModule_Helper_Data' not found in C:\xampp\apps\magento\htdocs\app\Mage.php on line 547

$this->renderLayout() doesn't give me an error.

IndexController:

class Package_MyModule_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
    }

    public function testAction() {
        $this->loadLayout();
        $this->renderLayout();
    }


    public function postAction() {
        $this->loadLayout();
        $this->renderLayout();
        //Mage_Core_Controller_Front_Action::loadLayout();
    }
}

I also tried to call the method directly out of the class Mage_Core_Controller_Front_Action but it still gives me the same error. indexAction() and testAction() do work as expected.

config.xml:

<config>
    <modules>
        <Package_MyModule>
            <version>0.3</version>
        </Package_MyModule>
    </modules>


    <frontend>

        <layout>
            <updates>
                <package_mymodule>
                    <file>mymodule.xml</file>
                </package_mymodule>
            </updates>
        </layout>

        <routers>
             <mymodule>
                <use>standard</use>
                  <args>
                     <module>Package_MyModule</module>
                     <frontName>mymodule</frontName>
                  </args>
             </mymodule>
        </routers>

    </frontend>


    <global>

        <models>
            <mymodule>
                <class>Package_MyModule_Model</class>
            </mymodule>
        </models>

        <helpers>
            <mymodule>
                <class>Package_MyModule_Helper</class>
            </mymodule>
        </helpers>

    </global>
</config>

app/code/local/Package/MyModule/Helper/Data.php:

class Package_MyModule_Helper_Data extends Mage_Core_Helper_Abstract {

}

/layout/mymodule.xml

<layout version="0.1.0">

    <mymodule_index_index>
        <reference name="content">
            <block type="core/template" name="default_mymodule_view" template="mymodule/view.phtml" />
        </reference>
    </mymodule_index_index>

</layout>

I think I got everything necessary at the right place. I have no idea why it isn't working inside postAction().

  • Why there is Mage in Mage_Package_MyModule_Helper_Data line? Could you add your full config.xml? – Adarsh Khatri Jun 25 '15 at 0:09
  • can you show your layout.xml file? – MeenakshiSundaram R Jun 25 '15 at 6:09
  • I added full config.xml and my layout.xml in the main post. – mpfmon Jun 25 '15 at 7:45
4

I'm quite sure you are using $this->__() inside of mymodule/view.phtml. Therefore you need a Helper_Data in your module.

In the config you have node global/helpers/mymodule, this node has to contain the Prefix of your helper, in this case MP_Berater_Helper (the same for the models.

And the name of the class has to be the same as the path, so either you rename your class to Package_MyModule_Helper_Data or you change the path to MP/Berater/Helper/Data.php

  • Was a mistake of mine, I changed the actuall Package and Module name (in the question) to "Package" and "MyModule" to keep things clear. I fixed it in the main post. – mpfmon Jun 25 '15 at 8:34
  • Did you clear your cache since updateing your config? – Fabian Blechschmidt Jun 25 '15 at 8:52
  • It's disabled in my testing enviroment. – mpfmon Jun 25 '15 at 9:05
  • then you should check where your helper is called from (stacktrace) and why it doesn't work. I think we can't help here. – Fabian Blechschmidt Jun 25 '15 at 9:41
2

Try to change your config.xml with the following:

<global>
    <models>
        <package_mymodule>
            <class>Package_MyModule_Model</class>
        </package_mymodule>
    </models>

    <helpers>
        <package_mymodule>
            <class>Package_MyModule_Helper</class>
        </package_mymodule>
    </helpers>

</global>
1

I fixed it though I dont know how. I had to reinstall magento. My installation must have been corrupted although it was pretty new. Same code is working on freshly installed magento.

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.