1

Synopsis

I notice this is a hot topic and so I did do my research before posting this question, please read.

I wanted to create myself an admin module and found a great article by Alan Storm, which I have successfully managed to get my admin controller working.

I also didn't need a menu item, so I omitted <menu> from the adminhtml.xml which also worked perfectly whilst my controller remained accessible.

My Question

So far my module is accessible via the following url: /admin/attachment/index/.

My controller is in: app/code/local/Vendor/ProductUploader/controllers/AttachmentController.php

How can I make my controller accessible via the following route? /admin/product_uploader/attachment/index

I presumed since Magento is build upon Zend I could create the following class; this didn't work: Vendor/ProductUploader/controllers/Product/Uploader/AttachmentController.php

1

You cannot do that.
The url must contain 3 parts [module]/[controller]/[action]. What you want is 4 parts.
The best you can do is to make it work on this url: admin/product_uploader_attachment/index.
For this it should work if you put your controller in Vendor/ProductUploader/controllers/Product/Uploader/AttachmentController.php.
[Off topic a little]
I also have recommendation if you allow it. Not that I question @AlanStorm's authority (I would never do that :D ), for consistency reasons I think it's best yo put your admin controllers inside an Adminhtml folder. This way you can easily tell which ones are for frontend and which for backend.
To do that you need to make your xml section that takes care of routing into this:

<routers>
    <adminhtml>
        <args>
            <modules>
                <Vendor_ProductUploader after="Mage_Adminhtml">Vendor_ProductUploader_Adminhtml</Vendor_ProductUploader>
            </modules>
        </args>
    </adminhtml>
</routers>

And you can place your controller in Vendor/ProductUploader/controllers/Adminhtml/Product/Uploader/AttachmentController.php

  • I didn't think it was possible, but thanks for clarifying it. Also I took your advice on the Adminhtml directory and updated the config.xml accordingly. It appears to work, I presume when I tried I didn't do something correctly - Thanks :) – ash Dec 18 '13 at 15:11
  • Just a reminder for those that use this product_uploader_attachment method to namespace the urls. Don't forget to update your controller class name and admin layout xml to accommodate the change. Ex. The class for the controller would change to Vendor_ProductUploader_Adminhtml_Product_Uploader_AttachmentController and the definition in your layout xml would end up being adminhtml_product_uploader_attachment_index. – jesseconnr Feb 28 '14 at 21:07

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.