How to redirect to an action in Magento?
HI,
I am trying to create a router for my custom module.
I would like to access index controller's hotsale action by url/hotsale. So I create the following router xml in my module's config.xml.
<hotsale>
<use>standard</use>
<args>
<module>Moon_Products</module>
<frontName>hotsale</frontName>
</args>
</hotsale>
when I access url/hotsale, it goes to index controller's index action. How do I make it to execute hotsale action?
I tried to add hotsale, but it didn't work.
I took Alan Storm's suggestion and ended with the following code.
public function indexAction()
{
if($this->getRequest()->getRouteName() == 'hotsale'){
$this->loadLay开发者_如何学运维out();
$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();
}
}
Default frontend/store routing works like this
http://example.com/front-name/controller-name/action-name
So, when you go to
http://example.com/hostsale
You're really saying
http://example.com/hostsale/index/index
The front-name concept is a little abstract, but in practice is ties a URL to a particular module.
So, if have an IndexController.php
with a method named hotsaleAction
, and you want to execute this method, use a URL in the form
http://example.com/hotsale/index/hotsale
精彩评论