4

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.

Reddy
  • 8,737
  • 11
  • 55
  • 73
Joel
  • 183
  • 1
  • 2
  • 8
  • Are you trying to have a url with the following structure... xyz.com/customcategory/what-ever-hyphnated-path-i-want.html ... xyz.com/customcategory/hyphnated-path-2.html ...etc ? – MagePal Extensions Nov 06 '12 at 01:26
  • Yes. So this way whatever controller file I work with within my custom controller, I can be given full control over that path. – Joel Nov 08 '12 at 16:59
  • Take a look at the "Product Tags" section and let me know if this is what your trying to accomplish http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-systems/isa-closet-system-shelves-hanging-walk-in-reach-in-closet.html – MagePal Extensions Nov 08 '12 at 17:06
  • YEs, so long as it is coming from my custom controller and not coming from a standard category url. Thanks. – Joel Nov 08 '12 at 19:51
  • That not a category url.. that a customization of the product tag module – MagePal Extensions Nov 08 '12 at 20:22

2 Answers2

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

MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • Very interesting. I will try this out this weekend. I cannot thank you enough for this. – Joel Nov 10 '12 at 14:05
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
madth3
  • 7,275
  • 12
  • 50
  • 74
Ian
  • 1,731
  • 15
  • 16
  • Interesting. That's a great point, just add a sub directory in the controller folder. Ok, so it's underscore instead of hyphen. It's good to know that I am able to confirm that it is not natural for Magento to allow the hyphen. I wasn't sure if I was just missing some 'trick' to make it work other than .htaccess magic. Thank you. – Joel Nov 05 '12 at 21:48