Magento -- System Configuration

Source: Internet
Author: User

Tomorrow's New Year. Haha!

 

1

 

How to obtain configuration data

Mage: getstoreconfig ('duan ', store_id), for example:

Mage: getstoreconfig ('helloworld _ options/message/hello_message ', 1 );

You can get the configuration in the sysytem. xml file, and then set the value in system-config in the background.

2

How to configure data.

2.1

First, specify helpers in config. XML, for example:

<Global>

<Helpers>

<Helloworld>

<Class> zh_helloworld_helper </class>

</Hellowordl>

</Helpers>

</Global>

2.1.1

The helpers class must be configured in the configuration.

Use helper

----------------------->

Mage: helper ('helloworld/foo ');

For the helpers class zh_helloworld_helper_foo used

For zh_helloworld_helper_data, you can directly get the data help class through Mage: helper ('helloworld;

 

 

2.1.2 help class instance:

APP/code/local/zh/helloworld/helper/data. php

Class zh_helloworld_helper_data extends mage_core_helper_abstract

{

}

 

3

Add a new section ):

In the ETC/system. xml file:

<Config>

<Tabs>

<Helloconfig translate = "label" module = "helloworld">

<Label> Hello config </label>

<Sort_order> 222 </sort_order>

</Helloconfig>

</Tabs>

 

<Sections>

<Helloworld_options translate = "label" module = "helloworld">

<Label> Hello World </Labe>

<Tab> helloconfig </TAB>

<Frontend_type> text </frontend_type>

<Sort_order> 1000 </sort_order>

<Show_in_default> 1 </show_in_default>

<Show_in_website> 1 </show_in_website>

<Show_in_store> 1 </show_in_store>

</Helloworld_options>

</Sections>

 

</Config>

4

Add ACL permissions:

ETC/config. xml

<Config>

<Adminhtml>

<ACL>

<Resources>

<Admin>

<Children>

<System>

<Children>

<Config>

<Children>

<Helloworld_options>

<Title> Store Hello World module section </title>

</Helloworld_options>

</Children>

</Config>

</Children>

</System>

</Children>

</Admin>

</Resources>

</ACL>

</Adminhtml>

</Config>

 

Analyze this code. All codes are defined as follows:

<Adminhtml>

<ACL>

<Resources>

</Resources>

</ACL>

</Adminhtml>

 

5

Add group:

In magento, options are divided by groups. Therefore, you must add a group before adding options and modify the system. xml file.

 

 <sections>        

 

6

Add configuration options:

 

<Messages translate = "label"> <label> demo of config fields </label> <frontend_type> text </frontend_type> <sort_order> 1 </sort_order> <show_in_default> 1 </show_in_default> <show_in_website> 1 </show_in_website> <show_in_store> 1 </show_in_store> <fields>     <label>Message</label>    <frontend_type>select</frontend_type>    < !– adding a source model –>    <source_model>helloworld/words</source_model>                               <sort_order>1</sort_order>    <show_in_default>1</show_in_default>    <show_in_website>1</show_in_website>    <show_in_store>1</show_in_store>                    

</Fields>
</Messages>

6.1
app/code/local/Zhlmmc/Helloworld/Model/Words.phpclass Zhlmmc_Helloworld_Model_Words{    public function toOptionArray()    {        return array(            array('value'=>1, 'label'=>Mage::helper('helloworld')->__('Hello')),            array('value'=>2, 'label'=>Mage::helper('helloworld')->__('Goodbye')),            array('value'=>3, 'label'=>Mage::helper('helloworld')->__('Yes')),            array('value'=>4, 'label'=>Mage::helper('helloworld')->__('No')),        );    }}

 

The source model provides the "tooptionsarray" method. The returned data is used to fill in the configuration options we previously defined. This method will be called by "initfields" at runtime. "Initfields" is defined in the following classes

app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
7
How to obtain configuration data

So far, we have only talked about how to set magento so that users can configure our modules. Now let's take a look at how to get the user's configuration data.

Mage::getStoreConfig('helloworld_options/messages/hello_message');

The above line of code can obtain the data of the "select" option we configured above. The parameter of this function is the URI of the data to be obtained. The format is as follows:

section_name/group_name/field_name

You can also use the following code to obtain all values of a group or segment:

Mage::getStoreConfig('helloworld_options/messages');Mage::getStoreConfig('helloworld_options');

Finally, if you want to obtain data for a specific store, you can pass in the store ID

Mage::getStoreConfig('helloworld_options',1);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.