Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Custom Module How to store variable in config.xml

I have a custom module that is working just fine but I would like to be able to store variables in the config so I can use them in my code. (For example a default error message)

I think I can access them by using Mage::getStoreConfig('/some/path/here'); but I don't know how to add them to the modules config.xml (myname/mymodule/etc/config.xml) so that I can use them in my code?

Anyone have a clue? Thanks!

like image 217
sulman Avatar asked Nov 22 '10 17:11

sulman


1 Answers

Reading these two articles should give you the information you need to add your own custom configuration variable, which will automatically give you a UI to enter values in the Admin.

If you want to set a default value for your new configuration variables, there's a top level config.xml node named default which will let you do that. Consider the following

<config>
    <!-- ... -->
    <default>
        <web>
            <default>
                <cms_home_page>home</cms_home_page>
                <cms_no_route>no-route</cms_no_route>
                <cms_no_cookies>enable-cookies</cms_no_cookies>
                <front>cms</front>
                <no_route>cms/index/noRoute</no_route>
                <show_cms_breadcrumbs>1</show_cms_breadcrumbs>
            </default>
        </web>
        <cms>
            <wysiwyg>
                <enabled>enabled</enabled>
            </wysiwyg>
        </cms>
    </default>
    <!-- ... -->
</config>

This structure in config.xml sets default values for the following config variables

web/default/cms_home_page
web/default/cms_no_route
web/default/cms_no_cookies
web/default/front
web/default/no_route
web/default/show_cms_breadcrumbs

cms/wysiwyg/enabled
like image 186
Alan Storm Avatar answered Oct 09 '22 07:10

Alan Storm