0

你好,

我正在尝试为我的自定义模块创建一个路由器。

我想通过 url/hotsale 访问索引控制器的 hotsale 操作。因此,我在模块的 config.xml 中创建了以下路由器 xml。

<hotsale>
 <use>standard</use>
 <args>
  <module>Moon_Products</module>
  <frontName>hotsale</frontName>
 </args>
</hotsale>

当我访问 url/hotsale 时,它​​会转到索引控制器的索引操作。如何使其执行热销操作?

我尝试添加热销,但没有奏效。

我接受了 Alan Storm 的建议,并以以下代码结束。

public function indexAction()
{
    if($this->getRequest()->getRouteName() == 'hotsale'){

        $this->loadLayout();    

        $block = $this->getLayout()->createBlock(
            'Mage_Core_Block_Template',
            'my_block_name_here',
            array('template' => 'moon/hotsale.phtml')
        );


        $this->getLayout()->getBlock('root')->setTemplate('page/product-without-rightbar.phtml');
        $this->getLayout()->getBlock('content')->append($block);

        $this->renderLayout();

    }
}
4

1 回答 1

2

默认的前端/存储路由是这样工作的

http://example.com/front-name/controller-name/action-name

所以,当你去

http://example.com/hostsale

你真的在说

http://example.com/hostsale/index/index

前端名称的概念有点抽象,但实际上是将 URL 与特定模块联系起来。

因此,如果有一个IndexController.php名为 的方法hotsaleAction,并且您想执行此方法,请使用表单中的 URL

http://example.com/hotsale/index/hotsale 
于 2010-09-30T02:12:01.963 回答