2012-11-05 37 views
4

比方說,我使用自定義控制器有Magento的路由器地址 - 需要Hyphnated路徑名

/customcategory 

好一個URL路徑/前端的名字,很明顯,如果我有一個名爲「TestController.php」控制器文件,的indexAction URL路徑將

/customcategory/test/index 

什麼,我想弄清楚是怎麼做重新命名該測試控制器,或者修改配置xml文件,所以我可以從控制文件中的連字符的URL如

/customcategory/test-section/index 

我知道如果我想/customcategory被連字符連接,我可以在配置文件中修改前端標籤。但是我正在構建的網站將受益於連字符控制器路線,這是/customcategory帶有關鍵字後的部分,我無法使其工作,也無法在Google上找到示例 - 就像看起來那麼瘋狂。

謝謝你的時間。

+0

你是不是想有以下結構的網址... XYZ .com/customcategory/what-ever-hyphnated-path-i-want.html ... xyz.com/customcategory/hyphnated-path-2.html ... etc? –

+0

是的。因此,無論我在自定義控制器中使用哪個控制器文件,我都可以完全控制該路徑。 – Joel

+0

查看「產品標籤」部分,讓我知道這是您試圖完成的任務http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-systems/isa-closet -system-shelves-hanging-walk-in-reach-in-closet.html –

回答

1

據我所知,您不能在url中添加超文本以匹配文件名。如果你想獲得一個文件夾結構,你可以添加更多的路徑。

例如,如果你想:

Namespace/CustomCategory/controller/test/SectionController.php 

你可以這樣做:

/customcategory/test_section/index 
+0

有趣。這是一個很好的觀點,只需在控制器文件夾中添加一個子目錄即可。好吧,它是下劃線而不是連字符。很高興知道我能夠確認Magento允許使用連字符是不自然的。我不確定我是否錯過了一些「技巧」,使它不僅僅是.htaccess魔術。 謝謝。 – Joel

1

你正在嘗試做你的自定義模塊,使用全球重寫是可能的。您可以將所有傳入的請求傳遞給/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-systems/isa-closet-system-shelves-hanging-walk-in-reach-in-closet.html

+0

非常有趣。我會在這個週末嘗試一下。我無法對此表示感謝。 – Joel