Magento xml configuration details

Source: Internet
Author: User
Tags administrator password

<? XML version = 1.0 "? <Config> <section> example of implementation example translate = "label"> <label> </label> <tab> General </label> <frontend_type> text </ frontend_type> <sort_order> 1000 </sorting order> <show_in_default> 1 </show_in_default> <strong> 1 </show_in_website> <show_in_store> 1 </show_in_store> </example> </Chapter> </configuration>

Some marked names are allsystem.xml, Which can be used in these parts, group and field definition:

  • EXAMPLEGiven a unique name, so it does not cover any other part. In reality, all lowercase names are the first choice.
  • labelIs the visible segment name.
  • tabIs the name of any existing title in the chapter list.
  • frontend_typeHere is alwaystextBut I am used to using a lot of things.
  • sort_orderTab. If the new part is omitted, it is replaced by an additional part.
  • show_in_default,show_in_website&show_in_storeShow or hide (1 or 0) different ranges are selected in the upper left corner of the "current configuration range" drop-down page. If either of them is omitted, it is set to 0.
  • commentYou can add your own comments to a field or group.

Groupsystem.xmlUse the specific tag name in:

  • expandedWhen a group is expanded, you can view the specific tag by default.

This is because it is a new page and the permissions required for page management. Next, create the fileCompany/Module/etc/adminhtml.xml.

<? XML version = 1.0 "? <Config> <acl> <resources> <ALL> <TITLE> allow ALL </TITLE> </> use <admin> <children> <SYSTEM> <children> <config> <children> (implementation example: translate = "title">) <TITLE> example section </TITLE> <sort_order> 100 </sort_order> </example> </children> </configuration> </children> </Management> </resource> </ACL> </configuration>

Note:admin,system configThe core module has been defined, so there is no need to define a title for these.

Add to existing section

If you want to appear in the configuration of some existing modules, and then use its name, it is not redefinedlabelsort_orderOr any other identifier. The existing part has been granted permissions.

<? XML version = 1.0 "? <Config> <section> <General> lower <! -Here you add: </General> </Chapter> </configuration>
Create a new group  

The Group is extended fieldsets in a section, and they are always children in a section. Edit yourCompany/Module/etc/system.xmlFile:

<? XML version = 1.0 "? <Config> <section> example of implementation example translate = "label"> <label> </label> <tab> </label> <frontend_type> text </frontend_type> <sort_order> 1000 </sorting order> <show_in_default> 1 </show_in_default> <show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> <groups> <! -Go to the new group-> <frontend_type> text </frontend_type> <sort_order> 100 </frontend_type> of <sample translate = "label"> <label> A </label> /sort_order> <show_in_default> 1 </show_in_default> <show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> </sample> </example> </ chapter> </configuration>
Create a new domain  

The field is in the same way as the children group, and the group is part of the children.

<? XML version = 1.0 "? <Config> <section> implementation example: translate = ""> <label> </label> <tab> </label> <frontend_type> text </frontend_type> <sort_order> 1000 </sorting order> <show_in_default> 1 </show_in_default> <show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> <groups> <sample translate <frontend_type> text </frontend_type> <sort_order> 100 </sort_order> <show_in_default> 1 </show_in_default> <Show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> <FIELDS> <! -Here is the new field.-> <ENABLED translate = "label comment"> <label> enable </label> <COMMENT> <! [CDATA [this text shows a field under a small arrow. <Span class = "notice"> it can contain HTML format! </SPAN>]> </comment> <frontend_type> select </frontend_type> <source_model> adminhtml/templates </source_model> <sort_order> 10 </sort_order> <show_in_default> 1 </show_in_default> <show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> </enable> </field> </sample> </example> </Chapter> </configuration>

commentIt is very useful to provide additional instructions or information. Wrap the text in the CDATA tag. If you want to use HTML,Any HTMLYes, but the most common purpose is to create a highlighted span "notification" or "warning" class.


Frontend_typeCan be any category/lib/Varien/Data/Form/Element/Directory. Here is just a few:

  • Button
  • Check box
  • Check box
  • Day
  • File
  • Hidden
  • Image File
  • Image
  • Tag
  • Link
  • Multiple rows
  • Multiple choice
  • Note:
  • Dark lines
  • Password
  • Radio
  • Radio
  • Reset
  • Select
  • Submit
  • TEXTAREA
  • Text
  • Time

Oppositefrontend_typeYou can also specify a typical block namemodule/path_to_fileFormat. This block will have_getElementHtml()Method call. Use this field to control the returned HTML.Even if it is calledfrontend_modelIt is indeed a block.


Provide possible options for all list fieldsMage/Adminhtml/Model/System/Config/SourceThe directory contains many useful sources that have been defined, such as "yes/no", "enable/disable", or you specify a model class. Country, currency, or language list.

You can also create your own source model and typicalmodule/path_to_fileFormat. Returns a nested array like this:

<? PHP class Company_Module_Model_Source {public function toOptionArray () {return array (Array ('value' => 0, 'tag' => Mage: helper () -> _ ('first Project'), array ('value' => 1, 'tag' => Mage: helper () -> _ ("item 2") array ('value' => 2, "tag" => Mage: helper () -> _ ("third item ")),//...);}}

The value saved in such a field will contain a string, such as the selected value of '1, 2, 3.


Field Configuration data is usually stored incore/config_dataModel, but you can also define your own. Its_afterLoad()The method is displayed before the call. It is called_beforeSave()_afterSave()Method When you click "Save configuration. When using the data of these events, an additional check may throw an exception in_beforeSave()Or update the local file in_afterSave()


validateThe label content is added as the final input element of a class. The following is a standard test of Form Verification for Magento.

  • Verify administrator password
  • Verify Ajax
  • Verify-α
  • Verify alphanum's
  • Verify CC-CVN
  • Verify CC-EXP
  • Verify the number of milliliters
  • Verify milliliters
  • Verify CC Selection
  • Verify the cleansing URL
  • Verification Code
  • Verify cpassword's
  • Verify CSS Length
  • Verify currency USD
  • Verify data
  • Verification date
  • Verification Date: Port-au-Prince
  • Verification number
  • Verify email
  • Verify Fax
  • Verification greater than zero
  • Verification ID
  • Verification Length
  • Verify New Password
  • Verification without a negative number
  • Verification number
  • Verification requirements
  • Verification requirements by name
  • Verify Password
  • Verify %
  • Verify mobile phone
  • Verify Selection
  • Verify SSN
  • Verification status
  • Verify Street
  • Verification URL
  • Verify the XML identifier
  • Verify zero or greater
  • Verify zipper
  • Verification ZIP Code International

This is very simpleCompany/Module/etc/config.xml:

<? XML version = 1.0 "? <Config> <DEFAULT> <example> <SAMPLE> set to Enabled 1 </enable> </SAMPLE> </example> </DEFAULT> </configuration>

HereENABLEDField has been adoptedadminhtml/system_config_source_yesnoThe source mode is defined as "no", and the values of '0' and '1' are "yes '. The default value is '1', which means that the enabled domain will be 'yes' until the user changes it.


The fastest way to access the saved field value is as follows:

Mage: getStoreConfig (for example,/sampling/enable ');

section/group/fieldThe format path is always under consideration.getStoreConfig()The default value is the website or store range.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.