将自定义表单元素添加到Adminhtml表单

编程入门 行业动态 更新时间:2024-10-12 05:53:35
本文介绍了将自定义表单元素添加到Adminhtml表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以将自定义表单元素添加到Magento Adminhtml表单中而无需将自定义元素放置在lib/Varian文件夹中?

Is there a way to add a custom form element to a Magento Adminhtml form without placing the custom element in the lib/Varian folder?

我已经找到了实质上是Varian_Data_Form_Element_工厂的代码

I've tracked down the code that's essentially a Varian_Data_Form_Element_ factory

public function addField($elementId, $type, $config, $after=false) { if (isset($this->_types[$type])) { $className = $this->_types[$type]; } else { $className = 'Varien_Data_Form_Element_'.ucfirst(strtolower($type)); } $element = new $className($config); $element->setId($elementId); if ($element->getRequired()) { $element->addClass('required-entry'); } $this->addElement($element, $after); return $element; }

因此,如果我正确地阅读了此内容,请确保EAV属性的前端返回特定的fieldType(例如supertextfield),并且在显示此属性的编辑表单时,系统将实例化/渲染Varien_Data_Form_Element_Supertextfield.

So, if I'm reading this correctly, I ensure that an EAV attribute's frontend returns a specific fieldType, (such as supertextfield) and the system will instantiate/render a Varien_Data_Form_Element_Supertextfield when displaying this attribute's editing form.

这很好,但是这意味着我需要在lib/Varian文件夹层次结构中包括我的自定义表单元素.考虑到面向模块的Magento的情况,看来这样做做错了.

This is well and good, but it means I need to include my custom form element in the lib/Varian folder hierarchy. Given how module oriented Magento is, it seems like this is doing it wrong.

我意识到我可以在库中使用custo autoloader或符号链接来解决问题,但是我主要是想了解是否有

I realize I could jank around with a custo autoloader or symlinks in the lib, but I'm primarily interested in learning if there's

  • 为属性添加自定义表单元素的规范方法

  • A canonical way to add custom form elements for attributes

    一种自定义Magento自动加载器的规范方法.

    A canonical way to customize the Magento autoloader.

    推荐答案

    自助服务台再次响起.看起来Magento设置包含路径的方式是,您可以从本地代码分支中的lib(而不仅仅是从Mage_名称空间)中删除类文件

    Self help desk strikes again. It looks like Magento sets up include paths in such a way that you can drop class files from lib (not just from the Mage_ namespace) in your local code branch

    app/code/local/Varien/etc

    当自动加载器尝试加载lib/Varien类时,它将首先检查您的目录.如果Varien创建与您的名字相同的数据元素,这仍然使您处于风险之中,但是随着风险的发展,它相对较低.

    When the autoloader tries to load a lib/Varien class, it will check your directory first. This still puts you at risk if Varien ever creates a data element with the same name as yours, but as risks go it's relatively low.

  • 更多推荐

    将自定义表单元素添加到Adminhtml表单

    本文发布于:2023-11-28 17:38:40,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1643339.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表单   自定义   元素   Adminhtml

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!