Magento路由器URL-需要连字符的路径名



假设我使用自定义控制器具有url路径/前端名称

/customcategory

好吧,显然,如果我有一个名为'testController.php'的控制器文件和索引。URL路径将为

/customcategory/test/index

我要弄清楚的是如何重新名称测试控制器或修改配置XML文件,因此我可以从控制器文件(例如

)中获得连字符URL
/customcategory/test-section/index

我知道,如果我希望 /customcategory与之连接,我可以在配置文件中修改 frontend 标签。但是,我正在建立的网站将受益于连字符控制器路线,这是/customcategory带有关键字的部分,我无法使其工作,也无法在Google上找到一个例子 - 看起来很疯狂。

感谢您的时间。

您要尝试使用自定义模块中的全局重写。您可以将/customcategory/*的所有传入请求传递给特定的控制器操作。但是您必须管理自己的路线(基于URL路径的深度)。

例如www.MageIgniter.com/customcategory/path1/path2

config.xml

<global>
    <rewrite>
      <fancy_url>
            <from><![CDATA[/customcategory/(.*)/]]></from>
            <to><![CDATA[customcategory/index/processroute/tagname/$1/]]></to>
            <complete>1</complete>
       </fancy_url>
    <rewrite>
</global>
<frontend>
    <routers>
        <tagseo>
            <use>standard</use>
            <args>
                <frontName>customcategory</frontName>
            </args>
        </tagseo>
    </routers>

class MageIgniter_Customcategory_IndexController extends Mage_Core_Controller_Front_Action
{
     public function processRoute(){
           print_r($requestUri = Mage::app()->getRequest()->getRequestUri()); //path1/path2
           print_r($this->getRequest()->getParam('tagname')); // path1
           print_r($this->getRequest())
           // do you custom logic here base on about request path explode('/', trim($requestUri,'/'))
     }
     ...

有关一个工作示例,请参见"产品标签"部分 @ http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-closet-systems/isa-closet-systems/isa-closet-system-system-system-system-system-shelves-hang-----------------------内在closet.html

据我所知,您不能在URL中添加低音以匹配文件名。如果您想获得一个文件夹结构,则可以向其添加更多路径。

例如,如果您想要:

Namespace/CustomCategory/controller/test/SectionController.php

您可以做:

/customcategory/test_section/index

最新更新