Magento Router Url - Need Hyphnated Path Name

2019-04-10 15:20发布

Let's say I use a custom controller to have a url path/frontend name of

/customcategory

Well, obviously if I have a controller file named 'TestController.php' and indexAction the url path would be

/customcategory/test/index

What I am trying to figure out is how I do re-name the Test Controller, or modify the config xml file, so I can have a hyphenated url from a controller file such as

/customcategory/test-section/index

I know that if I want /customcategory to be hyphenated, I can just modify the frontend tag in the config file. But the site I am building would benefit from a hyphenated controller route, the part that comes after /customcategory with keywords and I cannot get it to work nor can I find an example on google - as crazy as that may seem.

Thanks for your time.

2条回答
ら.Afraid
2楼-- · 2019-04-10 15:45

What you are trying to do is possible using global rewrite in your custom module. You could pass all incoming request for /customcategory/* to a specific controller action. But you would have to manage your own route (base on the depth of your url path).

e.g 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,'/'))

     }
     ...

For a working example see "Product Tags" section @ http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-systems/isa-closet-system-shelves-hanging-walk-in-reach-in-closet.html

查看更多
何必那么认真
3楼-- · 2019-04-10 15:52

As far as I am aware you cannot add hypens in the url to match up to a filename. If you are trying to get a folder structure you can just add more paths to it.

For example if you wanted:

Namespace/CustomCategory/controller/test/SectionController.php

you could do:

/customcategory/test_section/index
查看更多
登录 后发表回答