Magento: Add configuration menu item in the admin configrations
To add a configuration menu for a custom module in the admin configurations, you create or modify 4 files, adminhtml.xml, system.xml, config.xml and Data.php.
For demonstration, we will add a configuration menu item for an existing helloworld module and you can use the configuration page
in the admin panel to set the greeting text.
1. app/local/MyExtensions/Helloworld/etc/adminhtml.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <acl> <resources> <admin> <children> <system> <children> <config> <children> <helloworld_setting> <title>Hello World</title> </helloworld_setting> </children> </config> </children> </system> </children> </admin> </resources> </acl> </config>
2. app/local/MyExtensions/Helloworld/etc/system.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <tabs> <helloworld translate="label" module="helloworld"> <label>Hello World</label> <sort_order>99999</sort_order> </helloworld> </tabs> <sections> <helloworld_setting translate="label" module="helloworld"> <label>Settings</label> <tab>helloworld</tab> <frontend_type>text</frontend_type> <sort_order>99</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <groups> <greeting_settings translate="label"> <label>Greeting Settings</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> <enabled translate="label"> <label>Enabled</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_yesno</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> </enabled> <greeting translate="label,comment"> <label>Greeting</label> <frontend_type>text</frontend_type> <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> <comment>Greeting text.</comment> </greeting> </fields> </greeting_settings> </groups> </helloworld_setting> </sections> </config>
3. app/local/MyExtensions/Helloworld/etc/config.xml, you need to add the below in the global tag to specify the helper class
<helpers> <helloworld> <class>MyExtensions_Helloworld_Helper</class> </helloworld> </helpers>
4. app/local/MyExtensions/Helloworld/Helper/Data.php, this file can be empty but it just have to be there in order to be able to navigate to the helloworld configration page.
<?php class MyExtensions_Helloworld_Helper_Data extends Mage_Core_Helper_Abstract { } ?>
5. Clear the cache if you haven’t done so.
6. With the above 4 files in place and the cache cleared. We can now go to the helloworld configuration page by
Login to Admin Panel as an adminstrator -> System -> Configuration -> Settings under Hello World in the left Configuration menu -> Greeting Settings -> Enter some greeting text -> Save Config
7. To get the text we set in step 6.
//sectionName/groupName/fieldName echo Mage::getStoreConfig('helloworld_setting/greeting_settings/enabled'); echo Mage::getStoreConfig('helloworld_setting/greeting_settings/greeting');
Search within Codexpedia
Search the entire web