【问题标题】:How to use getUrl() in Magento to refer to another module?如何在 Magento 中使用 getUrl() 来引用另一个模块?
【发布时间】:2011-09-05 08:26:55
【问题描述】:

我在 Magento 管理面板中的模块的 URL 类似于 http://example.com/index.php/mymodule/... 并包含带有订单的自定义网格。当用户单击网格行时,我想将用户重定向到标准的“订单视图”页面。

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/... 而不是 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>

【问题讨论】:

  • @clockworkgeek 谢谢。请看我更新的帖子。它看起来类似于 config.xml 的情况,不是吗?
  • 您的frontNamemymodule,但如果您更仔细地复制示例,它将能够改用admin
  • 我的控制器有一个路径Foo/Mymodule/Adminhtml/MymoduleController.php 我尝试设置&lt;adminhtml&gt; &lt;args&gt;&lt;modules&gt;&lt;mymodule after="Mage_Adminhtml"&gt;Foo_Mymodule_Adminhtml_Mymodule&lt;/mymodule&gt; &lt;/modules&gt;&lt;/args&gt;&lt;/adminhtml&gt; 而不是当前配置,但尝试访问模块主页时http://example.com/index.php/admin/mymodule/mymodule/index 出现404 错误。

标签: magento geturl


【解决方案1】:

很简单,您只需将sales_order/view 替换为*/sales_order/view* 表示使用管理员中的当前路由器adminhtml

编辑
要更详细地解释,请将其放入您的配置中,

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

现在*/mymodule/index 的值将生成一个 URL http://example.com/index.php/admin/mymodule/index,该 URL 又将加载文件 Foo/Mymodule/controllers/Adminhtml/MymoduleController.php 并尝试查找方法 Foo_Mymodule_Adminhtml_MymoduleController::indexAction()。如果该方法存在,则运行它,否则管理路由器接管并显示 404 或重定向到仪表板。

【讨论】:

  • */sales_order/view 指向 http://example.com/index.php/mymodule/sales_order/view/。我也很惊讶。
  • 感谢您在上面的评论,我已经完全重写了布局配置中的路由和路径,所以现在使用*/sales_order/view 一切正常。
  • 你是如何重写的?我有完全一样的问题!使用 */sales_order/view 也会将我重定向到 index.php/mymodule/sales_order/view/ 而不是 index.php/admin/sales_order/view/。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 2021-09-08
  • 1970-01-01
  • 2018-06-18
  • 2021-03-14
  • 2013-05-08
相关资源
最近更新 更多