Magento allow us to configure and tweak the behavior of the site in the admin panel via system configuration. We can extend and use this feature in our custom modules too. This article describes the steps to achieve custom configuration in magento admin panel In this article We create and save our custom configuration message in our module. This module creates a custom tab and allows us to configure our own settings.
app/code/local/Mydons/Configdemo/etc/config.xml
<?xml version="1.0"?><config> <modules> <mydons_customconfig> <version>0.1.0</version> </mydons_customconfig> </modules><global> <helpers> <customconfig> <class>Mydons_Customconfig_Helper</class> </customconfig> </helpers></global><adminhtml> <acl> <resources> <admin> <children> <system> <children> <config> <children> <mydons translate="title" module="customconfig"> </mydons> </children> </config> </children> </system> </children> </admin> </resources> </acl> </adminhtml> </config>
Step 2: Create a Helper class as specified in the config.xml.
app/code/local/Mydons/Configdemo/Helper/Data.php
<?phpclass Mydons_Customconfig_Helper_Data extends Mage_Core_Helper_Abstract{
Step 3: To Create our own configuration setting, system.xml file needs to be created as shown below.
<config> <tabs> <mydons translate="label" module="customconfig"> <label>Mydons</label> <sort_order>100</sort_order> </mydons> </tabs> <sections> <mydons translate="label" module="customconfig"> <label>Mydons Config Demo</label> <tab>mydons</tab> <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> <groups> <mydonsconfigdemo translate="label"> <label>Mydons Config Demo</label> <frontend_type>text</frontend_type> <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> <fields> <mydons_message translate="label"> <label>Mydons Message</label> <frontend_type>text</frontend_type> <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> </mydons_message> </fields> </mydonsconfigdemo> </groups> </mydons> </sections></config> |
Mydons_Configdemo.xml needs to be placed in
app/etc/modules/Mydons_Configdemo.xml
<?xml version="1.0"?><config> <modules> <mydons_customconfig> <active>true</active> <codepool>local</codepool> </mydons_customconfig> </modules></config> http://example.com/configtest.php
Execute the file in the URL
<?php$mageFilename = 'app/Mage.php';require_once $mageFilename;umask(0);Mage::app();echo "<p style="color:green">";echo Mage::getStoreConfig('mydons/mydonsconfigdemo/mydons_message');echo "</p>"; |
No comments:
Post a Comment