如何在 Magento 中使用 getUrl() 引用另一个模块?
我在 Magento 管理面板中的模块的 URL 类似于 http://example.com/index.php/mymodule/< /a>... 并包含带有订单的自定义网格。当用户单击网格行时,我想将用户重定向到标准“订单视图”页面。
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;
}
但此 URL 指向 http://example.com/index.php/sales_order/view/< /a>...而不是 http://example.com/index.php/admin/sales_order/view/... 有什么建议吗?
UPD。 config.xml:
<admin>
<routers>
<mymodule>
<use>admin</use>
<args>
<module>Foo_Mymodule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
</admin>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很简单,您需要将
sales_order/view
替换为*/sales_order/view
。*
表示使用当前路由器,在管理中为adminhtml
。编辑
为了更详细地解释,请将其放入您的配置中,
现在值
*/mymodule/index
将生成一个 URLhttp://example.com/index.php/admin/mymodule/index
依次加载文件Foo/Mymodule/controllers/Adminhtml/MymoduleController.php
并尝试查找方法Foo_Mymodule_Adminhtml_MymoduleController::indexAction()
。如果该方法存在,则运行该方法,否则管理路由器接管并显示 404 或重定向到仪表板。Quite simply you need to replace
sales_order/view
with*/sales_order/view
. The*
means use the current router which in the admin isadminhtml
.Edit
To explain in more detail put this in your config,
Now the value
*/mymodule/index
will generate an URLhttp://example.com/index.php/admin/mymodule/index
which in turn will load the fileFoo/Mymodule/controllers/Adminhtml/MymoduleController.php
and try to find the methodFoo_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.