从magento的前端触发事件 [英] Trigger event from frontend in magento

查看:80
本文介绍了从magento的前端触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为(Ownmodule_Autocancel)的模块. 在此,我在名为autocancel/autocancel.phtml的模板文件的前端添加了一个按钮.该过程是,它应通过动作控制器重定向,例如"say hiwhn click on". 但是,当我单击该按钮时,它不会被触发.我不知道如何触发这里是autocancel.phtml

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>

我的controller.php文件是

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.

推荐答案

在模板中:

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

只需替换

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

<?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/';

只需阅读一些基本的Magento URL路由,您就可以开始工作了.

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

您的班级

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">

基本上你有..

MagentoBaseUrl + modulename/controllername/actionname

其中,modulename = autocancel,controllername = index,action = test.

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

希望这会有所帮助.

这篇关于从magento的前端触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆