2014-03-07 103 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。它会帮助你达到你想要的。