Magento-将一个按钮附加到system.xml并附加方法 [英] Magento - Add a button to system.xml with method attached to it

查看:64
本文介绍了Magento-将一个按钮附加到system.xml并附加方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模块,该模块的config.xml文件的模块cron区域中定义了一个定期运行的类似于导出"的方法.但我想通过在系统配置中添加立即运行"按钮,从而使用system.xml文件,使用户能够按需运行此导出方法.

I have created a module that has an "export like" method running regularly as defined in my module's cron area of the config.xml file. But I'd like to give the user the ability to run this export method on demand by adding a "Run now" button in the system configuration, thus using the system.xml file.

似乎前端类型"按钮可能已经按照我的尝试进行了工作,并且在配置部分添加了一个可点击的小按钮.但是我无法在按钮本身上附加方法或标签.

It seems that the "frontend type" button may be working as I've tried and it adds a tiny clickable button in the config section. But I am not able to attach a method nor a label on the button itself.

我曾考虑过在模块的"Grid.php"文件中添加一个按钮,但这不是我想要做的,因为它确实适合我的acl.

I thought about adding a button in the "Grid.php" file of the module but this not what I'd like to do as it does fit with my acl.

下面是我的system.xml文件,其前端类型为按钮".

Below is my system.xml file with the "button" frontend type.

有人对如何操作有任何了解吗?

Does anyone have a clue on how to :

  • 在按钮上添加标签/值
  • 将类添加到按钮
  • 添加单击按钮时要调用的方法

非常感谢您的帮助!

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

推荐答案

注意:自从这个问题以来,Magento一直在发展.请注意,此解决方案可能不适用于当前版本.

您应该尝试添加<frontend_model></frontend_model>. 例如:

You should try to add a <frontend_model></frontend_model>. For example :

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

然后创建要在其中复制的app/code/local/Foo/Bar/Block/Button.php:

And then create app/code/local/Foo/Bar/Block/Button.php in which you wil copy :

<?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;
    }
}
?>

感谢phy4me.

为了更好地了解正在发生的事情,请阅读核心资源:app/code/core/Mage/Adminhtml/Block/System/Config/Form.php initForm()函数和initFields()函数.

To better understand what's happening read core sources : app/code/core/Mage/Adminhtml/Block/System/Config/Form.php the initForm() function and initFields() function.

胡格斯

我移除了大写字母 更正了拼写错误

edit: I removed caps edit: corrected a spelling mistake

这篇关于Magento-将一个按钮附加到system.xml并附加方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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