在Magento中更改路由器

vie*_*ean 1 magento

我有如下链接:

index.php/catalog/product/offer/id/1/cid/100/
Run Code Online (Sandbox Code Playgroud)
  • id param表示产品的ID

  • cid param意味着客户的身份

现在,如果我想更改此链接,如何匹配路由器,如:

index.php/offer/id/1/cid/100/
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

clo*_*eek 6

如果你有一组有限的ID值,你可以创建相同数量的重写规则.这个想法是将每个可能的URL映射(即一对一)到缩短的形式.


但是,由于客户数量超出您的控制范围,因此使用Magento Wiki中描述的遗留XML重写可能会更好.

<config>
    ...
    <global>
        <rewrite>
            <vietean_catalog_product_offer>
                <from><![CDATA[#^offer/#]]></from>
                <to>catalog/product/offer/</to>
            </vietean_catalog_product_offer>
        </rewrite>
    </global>
</config>
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,第三个选项是形成index.php/offer?id=1&cid=100不那么漂亮的URL .然后,URL将转换为offer/index/index.为现有路由器指定前端名称offer,命名控制器IndexController和操作indexAction.

<config>
    ...
    <frontend>
        <routers>
            <vietean_example> <!-- This tag can be any unique value -->
                <use>standard</use> <!-- standard because it's the frontend -->
                <args>
                    <module>Vietean_Example</module>
                    <frontName>offer</frontName> <!-- First part of URLs -->
                </args>
            </vietean_example>
        </routers>
    </frontend>
</config>
Run Code Online (Sandbox Code Playgroud)

控制器可以以与以前完全相同的方式访问URL参数;

$id = $this->getRequest()->get('id');
$cid = $this->getRequest()->get('cid');
Run Code Online (Sandbox Code Playgroud)