In Depth Magento System Configuration(magento system.xml说明)

深入理解magento_V1.0.pdf 立即下载

Like this article? Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Last time we talked about Magento’s System Configuration system. If you missed it, you’ll want to go back and catch up. So, we glossed over a lot of the tags you could use within an individual field.

<fields>
    <!-- ... --->
    <fieldname translate="label">
        <label>Field Name</label>
        <frontend_type>text</frontend_type>
        <sort_order>2</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>0</show_in_store>
    </fieldname>
    <!-- ... --->
</fields>

Consider the rest of this article a thorough de-glossing.

<label/> and <comment/>

These tags allow you to set end-user facing text for your System Configuration field.

A label appears to the left of your form field, while a comment will appear directly under the field.

A label appears to the left of your form field, while a comment will appear directly under the field.

<show_in_default/>, <show_in_website/>, <show_in_store/>

These are boolean fields with a value of 1 or 0. They indicate if the field will show up when viewing the System Configuration in the default view, the website view, or the store view.

The implicit assumption is that they also control what options are configurable at each level. However, there’s nothing on the backend enforcing this assumption. That is, a field may be configured to with the following

<show_in_store> 0 </show_in_store>

but it will still be possible (although not advisable) to set and retrieve this field’s value at the store level via programatic means.

<sort_order/>

The <sort_order/> is a numerical value that’s used to determine the order of the fields within their group container. The higher the number, the lower the field will sort on the screen.

<frontend_type/>

<frontend_type/> determines the type of field that will be used to collect the configuration value. Values supported in Magento 1.4 Community Edition are

  1. allowspecific
  2. export
  3. image
  4. import
  5. label
  6. multiselect
  7. obscure
  8. password
  9. select
  10. text
  11. textarea
  12. time


The value of this field is used in a Factory style pattern to instantiate a class with a format of

Varien_Data_Form_Element_Type

where “Type” is the value of the <frontend_type/>’s text node. This happens in the addField method of theVarien_Data_Form_Element_Abstract class, as seen below

class Varien_Data_Form_Abstract extends Varien_Object
{
    //...
    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;
    }
}

<frontend_class/>

Don’t be fooled, <frontend_class/> is not a Grouped Class Name. The <frontend_class/> tag can be used to modify the class attribute of the form element tag that’s generated for your field. That is, this config field allows you to add a Cascading Stylesheet Class (i.e. “frontend” class) to the generated form element.

For example, a field configured with the following

<frontend_type>select</frontend_type>
<frontend_class>free-method</frontend_class>

will render as

<select class="free-method">

<validate/>

At first glance, <validate/> is a confusing configuration option. It appears to just add a CSS class to the generated tag. A configuration like this

<validate>validate-email</validate>

will yield a form element like this

<input type="text" class="validate-email" />

As with much of Magento, there’s more going on here. The presence of this CSS class will trigger the system’s client-side validation routines. For example, the above code would cause a javascript email validation to be run against the field. If the field fails the validation test, the end-user won’t be able to submit the configuration form.

You can take a look at the available validation routines in

js/prototype/validation.js

and here’s the above mentioned email validation routine from the same file

['validate-email', 'Please enter a valid email address. For example johndoe@domain.com.', function (v) {
            return Validation.get('IsEmpty').test(v) || /^[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+(\.[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})/i.test(v)
        }],

which looks to be a monstrous, but useful, regular expression.

<can_be_empty/>

The <can_be_empty/> tag is used with multiselect fields. The short version is, if you wish to a allow “no selection” to be a valid configuration, use this field.

What happens behind the scenes is if can_be_empty is true, the system renders a hidden field on the System Configuration page

File: lib/Varien/Data/Form/Element/Multiselect.php

if ($this->getCanBeEmpty()) {
    $html .= '<input type="hidden" name="' . parent::getName() . '" value="" />';
}

which ensure the form processing code will accept an empty selection.

<depends/>

<depends/> allows you specify that your configuration field should only be displayed when another confgiruation field in the same group has a specific value.

For example, the Paypal Express System Configuration has the following select defined.

<specificcountry translate="label">
    <label>Countries Payment Applicable From</label>
    <frontend_type>multiselect</frontend_type>
    <sort_order>110</sort_order>
    <source_model>adminhtml/system_config_source_country</source_model>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
    <depends><allowspecific>1</allowspecific></depends>
</specificcountry>

You’ll notice the

<depends><allowspecific>1</allowspecific></depends>

This is telling the system that if the <allowspecific> field (defined with the following)

<allowspecific translate="label">
   <label>Payment Applicable From</label>
   <frontend_type>select</frontend_type>
   <sort_order>100</sort_order>    <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
   <show_in_default>1</show_in_default>
   <show_in_website>1</show_in_website>
   <show_in_store>0</show_in_store>
</allowspecific>

has a value of “1”, then the <specificcountry> field should be displayed. This happens instantly via some behind the scenes Javascript.

While it appears to work with any fields that send out on onchange event, the core Magento system only uses this function where the parent field is a select. If you’re paranoid about forward compatibility, I’d apply the same restriction to your own System Configuration fields, as it’s hard to tell where the core Magento team may take this feature in the future.

<source_model/>

The <source_model/> tag specifies a Model class (in URI/Grouped Class Name format) to populate a field’s default options. As of Magento Community Edition 1.4x, it works with selects and multi-selects. In addition to the standard Magento Grouped Class Name, an extended syntax of

module/modelname::methodName

is supported. The system will instantiate a Model with getModel('module/modelname') and call its methodNamemethod to retrieve an array of value/label paris to use for the source. If the method name is left off, thetoOptionArray method will be called by default.

<frontend_model/>

By default, Magento Form Elements are rendered with the Block class

Mage_Adminhtml_Block_System_Config_Form_Field

However, if you want to use a custom renderer for your System Configuration field, you can specify a different block class (in URI/Grouped Class Name form) with the <frontend_model/> tag.

For example, the last_update field in the adminnotification group

<last_update translate="label">
    <label>Last update</label>
    <frontend_type>label</frontend_type>
    <frontend_model>adminhtml/system_config_form_field_notification</frontend_model>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
</last_update> 

specifies that a field renderer of adminhtml/system_config_form_field_notification should be used. This translates into the following class

File: app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Notification.php
class Mage_Adminhtml_Block_System_Config_Form_Field_Notification extends Mage_Adminhtml_Block_System_Config_Form_Field
{
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $element->setValue(Mage::app()->loadCache('admin_notifications_lastcheck'));
        $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
        return Mage::app()->getLocale()->date(intval($element->getValue()))->toString($format);
    }
}

The core team is overriding the _getElementHtml method to ensure that any entered date will be displayed with the same format.

<backend_model/>

Once a form is submitted to Magento, its values must be saved. For System Configuration fields, this is normally handeled with the Model class

Mage_Core_Model_Config_Data

However, there may be times where you want your System Configuration to use a different backend model. The<backend_model/> tag allows you to specify a different Model class (using URI/Grouped Class Name format).

Most often this isn’t because you want to save where the data is stored, but rather because you want to perform some additional action when a field is saved. By extending the Mage_Core_Model_Config_Data class with your own model and defining a _beforeSave and/or _afterSave method on your model, you can take additional action anytime a config value is changed.

For example, consider the import field in the tablerate group

<import translate="label">
    <label>Import</label>
    <frontend_type>import</frontend_type>
    <backend_model>adminhtml/system_config_backend_shipping_tablerate</backend_model>
    <sort_order>6</sort_order>
    <show_in_default>0</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
</import>

The Grouped Class Name adminhtml/system_config_backend_shipping_tablerate translates to the following class

class Mage_Adminhtml_Model_System_Config_Backend_Shipping_Tablerate extends Mage_Core_Model_Config_Data
{
    public function _afterSave()
    {
        Mage::getResourceModel('shipping/carrier_tablerate')->uploadAndImport($this);
    }
}

Here the core team is hooking into the _afterSave method (which is called after a model is saved) to update theshipping/carrier_tablerate Model with information from the just uploaded file.

<upload_dir/> and <base_url/>

Both these tags are used with System Configuration fields that use the <frontend_type>image</frontend_type>field with a <backend_model>adminhtml/system_config_backend_image</backend_model> backend model. These determine both

  1. Where the image file is uploaded
  2. The base URI path used when rendering an <img> tag

First, let’s cover the <upload_dir/> tag

<upload_dir config="system/filesystem/media" scope_info="1">sales/store/logo</upload_dir>

There’s three things being set by the above.

  1. The base image upload path
  2. The path, from the base, where this specific image field should be uploaded
  3. Whether or not the current config scope should be appended to the path

The base image upload path is set with the config attribute (system/filesystem/media above). This specifies a System Configuration path. That is, the base image upload path isn’t system/filesystem/media, but it’s the value of the Magento System Configuration at system/filesystem/media (which resolves to {{root_dir}}/mediain a default Community Edition install)

Once the base image upload path is found, we need to append the sub-directory this specific image should be uploaded to. To get this we append the value of the <upload_dir/>'s text node

sales/store/logo

to the value of the base image upload path, which will give us something like this

/path/to/magento/install/media/sales/store/logo

Finally, if the scope attribute is set to “1”, the current Configuration Scope will be transformed into a path. If you were uploading an image with the scope set to default, you’d get a path like

/path/to/magento/install/media/sales/store/logo/default

However, if you were uploading an image with the scope set to a specific store, you’d end up with a path like

/path/to/magento/install/media/sales/store/logo/stores/5

where “5” is the ID of the store scope you’re currently at.

When we upload an image, only the scope and image name portion of the path get saved to the config. This means we need to tell the System what the base URL should be for our image.

<base_url type="media" scope_info="1">sales/store/logo</base_url>

The scope_info and text node function the same as <upload_dir/>’s. Where <base_url/> differs is in setting thebase of the image URI (which is going to, naturally, be different than the local base file system path).

As you’ve likely intuited, the base path is set using the type attribute. The configured value will be passed into the getBaseUrl method on the global Mage object to set the base URL for the image. The the above example, that would look something like

Mage::getBaseUrl('media')

You can see the actual code that does this in the Mage_Adminhtml_Block_System_Config_Form_Field_Image class.

class Mage_Adminhtml_Block_System_Config_Form_Field_Image extends Varien_Data_Form_Element_Image
{
    //...

    protected function _getUrl()
    {
        $url = parent::_getUrl();

        $config = $this->getFieldConfig();
        /* @var $config Varien_Simplexml_Element */
        if (!empty($config->base_url)) {
            $el = $config->descend('base_url');
            $urlType = empty($el['type']) ? 'link' : (string)$el['type'];
            $url = Mage::getBaseUrl($urlType) . (string)$config->base_url . '/' . $url;
        }

        return $url;
    }

    //...
}

Finally, it’s important to note that this base URL is not used consistently throughout Magento to create a final URL for a configured image. From what I’ve seen this is only used to create an image preview within the System Configuration admin itself.

Wrapup

As you can see, the Magento System Configuration admin is a powerful system that’s almost an application development environment unto itself. By leveraging the functionality built into the system you can quickly and reliably build out new custom functionality for your, or your client’s stores.

来源:http://alanstorm.com/magento_system_configuration_in_depth_tutorial

深入理解magento Magento 模块开发教程 请求分发与控制器 布局、块和模板 模型和ORM基础 高级Magento模型 立即下载

相关推荐

YOLO26算法心电图十二导联目标检测+训练好的模型+368张数据集+pyqt可视化界面.zip

附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[导联I(I), 导联II(II), 导联III(III), 胸导联V1(V1), 胸导联V2(V2), 胸导联V3(V3), 胸导联V4(V4), 胸导联V5(V5), 胸导联V6(V6), 加压肢体导联aVF(aVF), 加压肢体导联aVL(aVL), 加压肢体导联aVR(aVR)] · 训练集:313 张 · 验证集:37 张 · 测试集:18 张 · 总计:368 张 该数据集聚焦于临床心电图信号的精准识别与定位,其核心检测目标为标准12导联心电图中的各个独立导联波形区域,涵盖肢体导联(I、II、III)与加压肢体导联(aVR、aVL、aVF),以及胸前导联(V1至V6),适用于心电图自动分析系统中对各导联位置的快速准确标注与分类。数据采集场景真实还原了医院心电图室或急诊监护环境下的标准心电图记录纸,波形清晰、基线稳定,具有高度临床参考价值。... 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 57 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9708** mAP50-95 | 0.6344 Precision | 0.8990 Recall | 0.9191 train/box_loss | 1.2231 train/cls_loss | 0.9703 val/box_loss | 1.2779 val/cls_loss | 0.... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。

magento XML配置文件的一些笔记及说明(更新中)

system.xml Some Options 1 ImageScroll Setting someoption text 40 1

Tiangsu 3460

企业级AI助手平台 开箱即用的全栈AI平台,支持多智能体协同、Supervisor模式编排、多种决策模式、RAG技术和流程编排能力 支持多厂商大模型统一接入与管理,安全可控的企业知识库与高精度检索优化

企业级AI应用开发框架,支持多厂商大模型统一接入与管理,安全可控的企业知识库与高精度检索优化能力,提供可视化流程编排、自主决策智能体与多智能体协同调度,兼容主流 Agent Skill 协议,帮助企业与开发者零门槛快速构建安全、高效、可落地的AI智能体应用与行业解决方案。

Magento 2 set up website with sub folder

Magento 2 official document是使用的subdomain, 但是i这次是使用 sub_folder mee233.local/es-ES mee233.local/it-IT 1. config at magento backend 2. create sub folder in pub/it-IT pub/es-ES foldermee233/pub/...

davissuperman的专栏 586

Android:Google三方库之Adjust集成详细步骤

Android为APP添加google adjust功能

学习就是我的个性 4473

基于深度强化学习的柔性作业车间动态调度

在追求敏捷和灵活的生产调度方面,处理不可预测的动态事件的能力变得越来越重要。与此同时,生产系统中的网络-物理融合产生了大量需要实时挖掘和分析的工业数据。为了便于这种实时控制,本研究提出了一种分层分布式的体系结构来解决动态柔性作业车间调度问题。采用双深度Q网络算法(DDQN)训练调度智能体,捕捉生产信息与调度目标之间的关系,为具有恒定任务到达的柔性作业车间实时做出调度决策。为了处理动态调度中问题的可变规格说明,提出了专门的状态和动作表示法。此外,还提出了一种代理奖励整形技术(surrogate reward

太剧烈的快乐与太剧烈的悲哀是有相同之点的——同样地需要远离人群! 1万+

magento2 常见问题与解决办法

所有命令要cd到magento2项目根目录后执行,虽然在bin也可能执行成功,但是会出现各种莫名其妙的问题。

Vandoer的博客 2352

complier lab2

只需支持定义 main 函数即可不带参数 int main(){...}带参数 int main(int argc, int argv){...}

qq_43581843的博客 904

Magento2 站点迁移后的典型故障处理

magento2站点迁移后,数据库无论是通过SQL转储还是通过管理软件传输,都会有个问题,其特点是报 The store that was requested wasn’t found. Verify the store and try again. 那么应该怎么解决这个问题呢?既然是站点那就免不了进行迁移操作,无论是将正在运行的站点拉到本地调试,还是将本地已经调试好的站点部署到服务器,又或者是将正在运行的站点更换服务器部署。然而经过一顿猛如虎的操作后,竟然发现迁移后的站点无法访问了!......

Vandoer的博客 566

记录汇川:自由口通信-梯形图

最常见的就是MODBUS通信协议,指令主要通过RS232和RS485端口进行报文发送,所以通信报文格式可以选择MODBUS RTU通信格式或MODBUS ASCII通信格式。255---Y10-Y17:ON(1111 1111)指令进行报文的发送与接收,但是报文内部的数据格式不是由主站PLC决定, 而是由。修改从站一个保持寄存器数据。修改从站多个保持寄存器数据。读取从站的输出信号状态。读取从站的输入信号状态。读取从站保持寄存器数据。读取从站输入寄存器数据。

m0_61837027的博客 4913

Zynq UltraScale+网络加速方案:用AXI Ethernet Subsystem实现2.5G吞吐量的配置秘籍

本文详细介绍了在Xilinx Zynq UltraScale+平台上使用AXI Ethernet Subsystem实现2.5Gbps网络吞吐量的配置方法。通过硬件设计优化、Vivado工程配置、Linux驱动调优及性能测试等关键步骤,为工业视觉和5G前传等高速网络应用提供可靠解决方案。

weixin_30485379的博客 614

magento2 提示 The default website isn‘t defined. Set the website and try again.

删除掉/app/etc/env.php和/app/etc/config.php即可。

weixin_38938932的博客 153

ArcGIS:根据DEM数据提取区域水系

利用DEM数据提取区域水系是常见的水文分析应用,为了获取区域的矢量水系数据,我们可以通过ArcGIS对高程DEM数据进行水文分析,为地表水流建立模型,进而获取到该地的水系数据,DEM数据精度越高,获取到的水系数据精度也就越高。以下介绍如何用ArcGIS提供的工具提取水系。

Oruizn的博客 9108

Mganeto 常见错误解决

magento 错误解决 转自http://hi.baidu.com/wolf_62/item/a5f963ede6f168eafb42ba6a magento安装域名出错Please enter a valid URL. Protocol is required 错误出现在magento1.5版中。 1.到网上查了一下,报错的直观原因是

matrixchan的专栏 3445

详解【计算机类&面试真题】军队文职考试——第7期:C盘格式化需要注意什么?| 两台笔记本连起来后ping不同,可能存在哪些问题?| 模拟信号到数字信号是如何转化的?| 计算机由哪些部件组成?

这是我分享的系列面试知识——军队文职(计算机类)面试真题详解(第7期)。本期分享:两台笔记本连起来后ping不同,你觉得可能存在哪些问题?模拟信号到数字信号是如何转化的?谈一谈计算机由哪些部件组成?如何加强计算机网络安全管理?若通过域名无法访问,而通过IP地址能访问。这是怎么回事?你将如何解决?谈一谈C盘格式化需要注意什么?开放类题目:如果应聘的岗位和你想的差距很远,你怎么办?

追光者♂:记录、分享、总结、提升,现象级专栏《Python从入门到人工智能》作者,无惧黑暗,坚信曙光 1917

QT应用编程: Win10系统下QT5.12搭建Android开发环境(配件齐全)

在win10系统下,搭建QT5.12.6 的Android开发环境。

7687

magento2开发中常见问题

1,Incompatible argument type: Required type: \Magento\Framework\DB\AdapterInterface 把 改成 2,Fatal error: Allowed memory size of xxx 内存不足的话,需要修改php.ini配置文件 memory_limit 设为1024M max_execution_time 设为360 3,The file "xxx/pub/media/tmp/catalog/product/i/n/i

2559

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深入理解Magento – 第一章 – Magento强大的配置系统

深入理解Magento – 第一章 – Magento强大的配置系统Magento的配置系统就像是Magento的心脏,支撑着Magento的运行。这套配置系统掌管着几乎所有“module/model/class/template/etc”。它把整个Magento系统抽象出来,用一个配置文件来描述。这里的“配置文件”并不是一个物理上存在的文件,而是Magento根据当前的系统状态动态生成的一段XML。大多数的PHP开发者并不习惯于这样抽象层,因为它增加的编程的复杂性。但是这样的抽象提供了无与伦比的灵活性,允

Terry - 专注外贸B2C 874

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

第一章 – Magento强大的配置系统

Magento的配置系统就像是Magento的心脏,支撑着Magento的运行。这套配置系统掌管着几乎所有“module/model/class/template/etc”。它把整个Magento系统抽象出来,用一个配置文件来描述。这里的“配置文件”并不是一个物理上存在的文件,而是Magento根据当前的系统状态动态生成的一段XML。大多数的PHP开发者并不习惯于这样抽象层,因为它增加的编程的复杂

suese的专栏 1210

第九章-修改、扩展、重写Magento代码

重写Magento模块(Module)   第一步,你需要创建属于你自己代码的命名空间,例如Wemvc,App等,为了方便与大家分享代码,我将空间命名为App 。 C代码   app/        code/               core/               community/               local/      

suese的专栏 1073

magento开发 -- 深入理解Magento第二章

 第二章 - Magento请求分发与控制器Model-View-Controller (MVC) ,模型-视图-控制器,源于Smalltalk编程语言和Xerox Parc。现在有很多系统是基于MVC架构的,不同的系统MVC的实现也略有不同,但都体现了MVC的精髓,分离数据,业务逻辑和显示逻辑。最常见的PHP MVC框架是这样的URL请求被一个PHP文件拦截,通常称为前端控制

水水的Magento专栏 4884

第一章 深入理解Magento - Magento强大的配置系统

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34252090的博客 156

magento在后台form里面添加css和js

在后台创建的html元素,一般都是在function _prepareForm()里面调用addField; 如下代码创建一个button $buttonstyle = " padding-left:6px; border-color:#ED6502; text-align:center; "; $fieldset = $form-

jonas的magento博客 2550

magento 2.4 windows平台需要修改代码记录

1、vendor\magento\framework\View\Element\Template\File\Validator.php protected function isPathInDirectories($path, $directories) { if (!is_array($directories)) { $directories = (array)$directories; } //$realPat.

CyrusZhou的专栏 1674
上一篇: magento XML配置文件的一些笔记及说明(更新中)
下一篇: MySQL拼音首字母查询
神灵舞师
博客等级 码龄15年 4粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值