Search code examples
magentomagento-1.5

How to get the URL of a page/section in Magento admin


I can't seem to find a definitive answer on this one. How do you get a url to a page in the admin backend?

For example, let's say I have a module that uses a controller with a frontname of mymodule. If I call:

$this->getUrl('mymodule/controller/action')

I get:

http://mydomain.com/index.php/mymodule/controller/action

This doesn't work because it doesn't have the admin frontname included.

I found this thread that mentions using this:

Mage::helper("adminhtml")->getUrl();

However that doesn't append the admin frontname to the URL either...so what's the point of passing it through the adminhtml helper? The thread also says you can use this to get the admin frontname:

Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName');

So am I supposed to build the correct URL using these 2 methods or is there an easier way to accomplish this? I would figure there has to be an easy way, but I just can't figure it out.

Thanks :)


Solution

  • I think I figured this one out, but please comment or add your own answer if I'm mistaken. My first issue was that my config.xml was configured incorrectly. I had <frontend> instead of <admin> under the <routers> element. I also had <use>standard</use> instead of <use>admin</use>. Copy-Paste mistake ;)

    However, that still didn't seem to change the URL being returned, but that doesn't seem to matter. It's now correctly hitting my controller, even though the url I'm redirecting to doesn't contain the admin frontname. So I'm a bit confused about that, but regardless, it's working.