Magento Router Url - Need Hyphnated Path Name

╄→尐↘猪︶ㄣ 提交于 2019-12-09 18:32:08

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/13238428/magento-router-url-need-hyphnated-path-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!