0

I am creating my first custom module for magento and I already have some issues. What I am trying to do is to create new section under catalog tab in admin panel (this I already made) but when I clicked my custom section it does not finds route (or in other words it not finds index action) and I get redirected to 404 error page.

Here is what I already have: app/etc/modules/Company_myModule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_myModule>
            <active>true</active>
            <codePool>local</codePool>
        </Company_myModule>
    </modules>
</config>

app/code/local/Company/myModule/controllers/Adminhtml/ReportController.php

<?php

class Company_myModule_Adminhtml_ReportController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
    echo "test";
    }
}

app/code/local/Company/myModule/etc/config.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Company_myModule>
            <version>1.0.0</version>
        </Company_myModule>
    </modules>
    <global>
        <helpers>
            <Company_myModule>
                <class>Company_myModule_Helper</class>
            </Company_myModule>
        </helpers>
    </global>   
</config>

app/code/local/Company/myModule/etc/adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <menu>
        <catalog>
             <children>
                <myModule translate="title" module="company_myModule">
                    <title>myModule title</title>
                    <sort_order>2</sort_order>     
        <action>adminhtml/report</action>
                </myModule>
             </children>
    </catalog>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <catalog>
                    <title>myModule title</title>
                    <sort_order>2</sort_order>
                </catalog>
            </children>
        </admin>
    </resources>
</acl>
</config>

Any ideas why it not able to find route to my index action in ReportController ?

2 Answers 2

2

You need to set up a Helper

app/code/local/Company/myModule/Helper/Data.php

<?php
class Company_myModule_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Also, you'll need to add a router to your page in config.xml, like this:

....
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Company_myModule before="Mage_Adminhtml">Company_myModule_Adminhtml</Company_myModule>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
....
2
  • There is a user on StackExchange called Marius who also developed something extremely impressive for helping you set up new modules, have a look: magentocommerce.com/magento-connect/utilities/developer-tools/… I find that the MagentoCommerce boards offer extremely useful & accurate guides: tinyurl.com/3f7wpxs
    – Moose
    Commented Feb 6, 2014 at 9:54
  • Sorry, I forgot to paste my helper file. But you was right I was missing router in my config.xml file and adding it helped me solve the problem. Thanks, you saved my time ;) Also thanks for the useful resources. :)
    – intentarr
    Commented Feb 6, 2014 at 10:04
0

You are missing the router declaration in your module.
In config.xml add this as a sibling node for <global>.

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Company_myModule before="Mage_Adminhtml">Company_myModule_Adminhtml</Company_myModule>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

And make sure you place your controller in app/code/local/Company/myModule/controllers/Adminhtml/ReportController.php.
I also suggest not naming your controller ReportController.php there is already a file with that name in Mage/Adminhtml/controllers and your controller might override the core one.

1
  • Thanks for answering my question, you and moose both was right telling that I was missing route in my module. Thanks for advice naming my controller, I will rename it :)
    – intentarr
    Commented Feb 6, 2014 at 10:06

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.