Change Router in Magento
I have a link like below:
index.php/catalog/product/offer/id/1/cid/100/
id
param means the id of productcid
param means the id of customer
Now if I want to change this link how to match with a router like:
index.php/offer开发者_StackOverflow中文版/id/1/cid/100/
How can I do that?
If you have a finite set of ID values you can create an equal number of rewrite rules like this. The idea there is to map (ie. one-to-one) every possible URL to a shortened form.
However since the number of customers is out of your control it might be better to use a legacy XML rewrite as described in the Magento Wiki.
<config>
...
<global>
<rewrite>
<vietean_catalog_product_offer>
<from><![CDATA[#^offer/#]]></from>
<to>catalog/product/offer/</to>
</vietean_catalog_product_offer>
</rewrite>
</global>
</config>
If that doesn't work the third option is to form URLs like index.php/offer?id=1&cid=100
which isn't as pretty. The URL will then translate into offer/index/index
. Give your existing router the front name of offer
, name the controller IndexController
and the action 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>
The controller can access the URL parameters in the exact same way as before;
$id = $this->getRequest()->get('id');
$cid = $this->getRequest()->get('cid');
精彩评论