duanaoou4105 2015-03-27 06:13
浏览 9

从magento的前端触发事件

I have created a module with name as (Ownmodule_Autocancel). In this i added a button to front end at template file named as autocancel/autocancel.phtml.The process is,it should redirect by action controller like "say hiwhn click on it". But when i click on that button it is not triggered. I don't know how to trigger that here is autocancel.phtml

<form method="post" action = "<?php echo Mage::getUrl(); ?>" id="cancelorder">
<button type ="button" title="<?php echo $this->__('Cancel Pickup') ?>" class="button btn-checkout" onclick="setLocation('<?php echo Mage::registry('token'); ?>')"><span><span><?php echo $this->__('Cancel Pickup') ?></span></span></button></p>

And my controller.php file is

<?php
class Ownmodule_Autocancel_IndexController extends Mage_Core_Controller_Front_Action
{public function IndexAction(){
$this->loadLayout();
$this->getLayout()->getBlock('head')->setTitle($this->__('autocancel'));
//echo $this->getLayout()->createBlock('core/tempete')->setTemplete('autocancel/autocancel.phtml')->toHtml();
    $this->renderLayout();
}

} ?>

It just show undefined page when click on that button.

  • 写回答

1条回答 默认 最新

  • douzhao7014 2015-03-27 06:24
    关注

    In Template:

    <form method="post" action = "<?php echo Mage::getUrl(); ?>" id="cancelorder">
    

    Just replace

    <?php echo Mage::getUrl(); ?>
    

    with

    <?php echo Mage::getBaseUrl(); ?>
    

    and you should be redirected to the home page.

    So if you create another action in you custom controller then, just append to the base url like,

    echo Mage::getBaseUrl().'/autocancel/CONTROLLER/NEWACTION/';
    

    Just read some basic Magento URL routing and u should be up and ready to go.

    UPDATED

    Your Class

    class Ownmodule_Autocancel_IndexController extends Mage_Core_Controller_Front_Action
    {public function IndexAction(){
    $this->loadLayout();
    $this->getLayout()->getBlock('head')->setTitle($this->__('autocancel'));
    //echo $this->getLayout()->createBlock('core/tempete')->setTemplete('autocancel/autocancel.phtml')->toHtml();
        $this->renderLayout();
    }
    
    //add another action
    public function testAction(){
    die('test');
    }
    

    To reach to this new action in your controller

    <form method="post" action = "<?php echo Mage::getBaseUrl(); ?>/autocancel/index/test" id="cancelorder">
    

    Basically you have..

    MagentoBaseUrl + modulename/controllername/actionname
    

    where, modulename = autocancel, controllername = index , action = test .

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?