0

我正在尝试在 Magento 中创建我的第一个模块。

我不能做的事情是按照我想要的方式定义模块的路由。

我想创建一个路由“网关/iphone”,但它不起作用。是否可以在路由定义中使用“/”?

这是我的模块定义:

<?xml version="1.0" encoding="UTF-8"?>
<config>    
    <modules>
        <Nacho_GatewayIphone>
            <version>0.1.0</version>
        </Nacho_GatewayIphone>
    </modules>
    <frontend>
        <routers>
            <nacho_gatewayiphone>
                <use>standard</use>
                <args>
                    <module>Nacho_GatewayIphone</module>
                    <frontName>gateway_iphone</frontName>
                </args>
            </nacho_gatewayiphone>
        </routers>  
    </frontend>
</config>

它在 /gateway_iphone 中运行良好,但是如果我将<frontName>值更改为<frontName>gateways/iphone</frontName>尝试点击 /gateways/iphone 时它​​不会运行。

是否可以在路由器定义中使用“/”字符?

4

3 回答 3

2

由于 Magento 将 URL 解析为 get router/controller/action,因此您不能真正使用/指定路由器,因为它会违反上述结构。

答案很简单,为什么不将网关指定为路由器,将iphone指定为控制器呢?您仍然需要为您的模块设置一个控制器,因此IndexController您可以IphoneController使用gateways作为路由器创建,而不是创建,并gateways/iphone在 url 中获得所需。

于 2012-09-28T06:48:34.557 回答
1

如果您需要更复杂的 URL,那么可以使用基于正则表达式的重写方法。例如,您可以将以下内容添加到您的 config.xml:

<global>
    <rewrite>
        <nacho_gatewayiphone_example>
            <from><![CDATA[#^/such/a/long/example/for/an/url/path/#]]></from>
            <!-- Assuming that "gateways" is now the frontName -->
            <to>/gateways/example_controller_name/</to>
        </nacho_gatewayiphone_example>
        <!-- Other rewrites for nacho here -->
    </rewrite>
</global>

有关更多详细信息,请参阅此 wiki或有关更多信息,请参阅此博客

于 2012-09-28T11:11:20.387 回答
-1

您应该必须将您的模块从 重命名Nacho_GatewayIphoneNacho_Gateway_Iphone.

对文件夹结构和类名进行必要的调整。

于 2012-09-28T05:50:21.187 回答