题
你好,
我正在尝试为我的自定义模块创建路由器。
我想访问URL/HOTSALE的索引控制器的Hotsale Action。因此,我在模块的config.xml中创建以下路由器XML。
<hotsale>
<use>standard</use>
<args>
<module>Moon_Products</module>
<frontName>hotsale</frontName>
</args>
</hotsale>
当我访问URL/HOTSALE时,它将用于索引控制器的索引操作。我该如何执行热门行动?
我试图添加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();
}
}
解决方案
默认前端/商店路由这样的工作
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
不隶属于 StackOverflow