1

I want to create an admin controller - without having any menu items associated with it.

Ideally I want to have my controller accessible via /index.php/admin/my_controller/.

So far I have rewritten the adminhtml controller as follows but i simnply get a 404 inside the admin console (i.e. not the main 404 page):

    <admin>
    <routers> 
        <my_module>
            <use>admin</use>
            <args>
                <module>Me_Mymodule</module>
                <frontName>my_controller</frontName>
            </args>
        </my_module>
         <adminhtml>
            <args>
                <modules>
                    <my_module after="Mage_Adminhtml">Me_Mymodule</my_module>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
Marty Wallace
  • 34,046
  • 53
  • 137
  • 200

3 Answers3

3

Your current config technique has been obsolete since version 1.4. Instead it is more convenient to structure it like this.

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <my_module before="Mage_Adminhtml">Me_Mymodule_Adminhtml</my_module>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Then to get the /index.php/admin/mymodule/ path create the class Me_Mymodule_Adminhtml_MymoduleController extends Mage_Adminhtml_Controller_Action in Me/Mymodule/controllers/Adminhtml/MymoduleController.php. In your example you used an underscore in the controller name, be careful of that as it will be used as a directory separator when searching for the correct class.

Remember to generate URLs for your controller like Mage::getUrl('adminhtml/mymodule') so that it adds the secret key to paths, this is necessary when making an admin controller or it will refuse the page.

If there are no menu items then it will not be possible to add them to the ACL. You do not need an adminhtml.xml file in this case.

Community
  • 1
  • 1
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
  • The OP config is correct. The first part is a bit extraneous, but overall is correct... – benmarks Mar 18 '12 at 12:16
  • One notice. Better use after="Mage_Adminhtml" to avoid unintentionally overriding of magento module. – Sergey Mar 18 '12 at 19:37
  • @Sergy That is my habit because sometimes you need to override core controllers. Thanks for pointing it out and the OP has the option of which to use. – clockworkgeek Mar 18 '12 at 22:25
0

Even if you do not add your controller to menu, you still have to add acl section for your controller adminhtml.xml. Do not forget to relog to admin after that.

Dmytro Zavalkin
  • 5,265
  • 1
  • 30
  • 34
0

For you goal xml config is redundant. Use following to add your controller to /admin frontname Company_Module_Adminhtml
Now every controller that will be created in controller/Adminhtml folder will accessed through admin like

/admin/yourfilename/index

The class name of controller should be Module_Module_Adminhtml_YourfilenameController and should extend Mage_Adminhtml_Controller_Action That's the trick.

Sergey
  • 1,494
  • 10
  • 14