Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use getUrl() in Magento to refer to another module?

Tags:

magento

geturl

My module in Magento adminpanel has URL like as http://example.com/index.php/mymodule/... and contains custom grid with the orders. I want to redirect user to the standard "Order view" page when he clicks on a grid row.

public function getRowUrl($row)
{
    if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        return $this->getUrl('sales_order/view', array('order_id' => $row->getId()));
    }
    return false;
}

But this URL points to http://example.com/index.php/sales_order/view/... instead of http://example.com/index.php/admin/sales_order/view/... Any suggestion?

UPD. config.xml:

<admin>
    <routers>
        <mymodule>
            <use>admin</use>
            <args>
                <module>Foo_Mymodule</module>
                <frontName>mymodule</frontName>
            </args>
        </mymodule>
    </routers>
</admin>
like image 772
silex Avatar asked Sep 05 '11 08:09

silex


People also ask

How do I add a YouTube video to my Magento product page?

Navigate to Images and Videos section of Product and click on Add Video. Enter the Product video URL from YouTube. If the API key is invalid or you haven't added it yet, you will get an error message. After adding product video URL, click to save and jump back to the product page to check the video added.


1 Answers

Quite simply you need to replace sales_order/view with */sales_order/view. The * means use the current router which in the admin is adminhtml.

Edit
To explain in more detail put this in your config,

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <mymodule after="Mage_Adminhtml">Foo_Mymodule_Adminhtml</mymodule>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Now the value */mymodule/index will generate an URL http://example.com/index.php/admin/mymodule/index which in turn will load the file Foo/Mymodule/controllers/Adminhtml/MymoduleController.php and try to find the method Foo_Mymodule_Adminhtml_MymoduleController::indexAction(). If the method exists it is run, otherwise the admin router takes over and shows a 404 or redirects to the dashboard.

like image 168
clockworkgeek Avatar answered Oct 04 '22 00:10

clockworkgeek