Magento-将一个按钮添加到system.xml,并附加一个方法
我创建了一个模块,该模块有一个“类似导出”的方法,按照config.xml文件中模块的cron区域中的定义定期运行。但是我希望通过在系统配置中添加一个“runnow”按钮,从而使用system.xml文件,让用户能够根据需要运行这个导出方法 似乎“前端类型”按钮可以像我尝试的那样工作,它在配置部分添加了一个小的可点击按钮。但我无法在按钮本身上附加方法或标签 我曾考虑在模块的“Grid.php”文件中添加一个按钮,但这不是我想要做的,因为它确实适合我的acl 下面是我的system.xml文件,其前端类型为“button” 是否有人知道如何:Magento-将一个按钮添加到system.xml,并附加一个方法,magento,Magento,我创建了一个模块,该模块有一个“类似导出”的方法,按照config.xml文件中模块的cron区域中的定义定期运行。但是我希望通过在系统配置中添加一个“runnow”按钮,从而使用system.xml文件,让用户能够根据需要运行这个导出方法 似乎“前端类型”按钮可以像我尝试的那样工作,它在配置部分添加了一个小的可点击按钮。但我无法在按钮本身上附加方法或标签 我曾考虑在模块的“Grid.php”文件中添加一个按钮,但这不是我想要做的,因为它确实适合我的acl 下面是我的system.xml文件,其
- 向按钮添加标签/值
- 向按钮添加一个类
- 添加单击按钮时要调用的方法
<?xml version="1.0" encoding="UTF-8"?>
<config>
...
<fields>
...
<run translate="label">
<label>Run now</label>
<frontend_type>button</frontend_type>
<backend_model>SOME BACKEND MODEL</backend_model>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</run>
</fields>
...
</config>
...
...
快跑
按钮
一些后端模型
20
1.
1.
1.
...
注意:自从这个问题出现以来,Magento已经进化了。请注意,此解决方案在当前版本中可能不起作用
您应该尝试添加一个
。
例如:
<?xml version="1.0" encoding="UTF-8"?>
<config>
...
<fields>
...
<run translate="label">
<label>Run now</label>
<frontend_type>button</frontend_type>
<frontend_model>bar/button</frontend_model>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</run>
</fields>
...
</config>
...
...
快跑
按钮
栏/按钮
20
1.
1.
1.
...
然后创建app/code/local/Foo/Bar/Block/Button.php,在其中复制:
<?php
class Foo_Bar_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$this->setElement($element);
$url = $this->getUrl('catalog/product'); //
$html = $this->getLayout()->createBlock('adminhtml/widget_button')
->setType('button')
->setClass('scalable')
->setLabel('Run Now !')
->setOnClick("setLocation('$url')")
->toHtml();
return $html;
}
}
?>
Hugues answer成功了。 但需要注意的一点是,前端_模型动作不能有上限 这一定是
<frontend_model>bar/button</frontend_model>
3) 创建/编辑了Foo_Bar管理控制器的操作,在该操作中,我使用
Mage::getModel('bar/block')->method();
并向adminhtml区域添加了一个重定向,我希望将用户重定向到该区域(在我的示例中是config的carriers部分):
一切都在流动
再次感谢
$url = $this->getUrl('bar/adminhtml_controller/action');
Mage::getModel('bar/block')->method();
$this->_redirect('adminhtml/system_config/edit/section/carriers');