开发者

How to redirect to an action in Magento?

开发者 https://www.devze.com 2023-01-18 07:42 出处:网络
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.

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号