2014-03-07 102 views
0

我創建了自己extenstion這是組合,這裏配置爲前端:Magento的路由孩子

<frontend> 
     <routers> 
      <portfolio> 
       <use>standard</use> 
       <args> 
        <module>xxx_Portfolio</module> 
        <frontName>portfolio</frontName> 
       </args> 
      </portfolio> 
     </routers> 
     <layout> 
      <updates> 
       <portfolio> 
        <file>portfolio.xml</file> 
       </portfolio> 
      </updates> 
     </layout> 
    </frontend> 

因此被解僱了在URL基地/組合 ,但我想在每一個項目中創建路線投資組合,所以網址將是: base/portfolio/project1 base/portfolio/project2

我該如何做到這一點?

回答

1

你可以做到這一點使用下面的示例代碼

class Namespace_Portfolio_IndexController extends Mage_Core_Controller_Front_Action 
{ 
    public function indexAction() 
    { 
    echo 'test index';// its your working code that you access from [base-url]/portfolio 
    } 
} 

針對你的情況的第一個項目(控制器)在控制器文件夾中創建新的文件

[magento]\app\code\[codepool]\[Namespace]\[Portfolio]\controllers\Project1Controller.php 



class Namespace_Portfolio_Project1Controller extends Mage_Core_Controller_Front_Action 
    { 
     public function indexAction() 
     { 
     echo 'welcome to project1';// its your working code that you access from [base-url]/portfolio 
     } 
    } 

同爲項目2 [magento]\app\code\[codepool]\[Namespace]\[Portfolio]\controllers\Project2Controller.php

class Namespace_Portfolio_Project2Controller extends Mage_Core_Controller_Front_Action 
    { 
     public function indexAction() 
     { 
     echo 'welcome to project2';// its your working code that you access from [base-url]/portfolio 
     } 
    } 

希望這對你有所幫助。

注:我的建議是爲您的需求使用相同的控制器動作而不是創建新的控制器&使用url-rewrite。它會幫助你達到你想要的。