0

I have created a very simple module for Magento. All that I have done so far is declared a module and created its config.xml file. I am trying to read the xpath from the file, however nothing is showing up. The directory is correct and all files are in their place. Does anyone know what the problem might be, because I'm quite new to Magento and I have spent hours googleing it.

<!-- First_Module.xml -->
<!-- Path : app/etc/modules -->

<?xml version="1.0"?>
<config>
      <modules>
            <First_Module>
                  <active>true</active>
                  <codePool>local</codePool>
            </First_Module>
      </modules>
</config>

<!-- config.xml -->
<!-- Path : app/code/local/First/Module/etc/ -->

<?xml version="1.0"?>
<config>
      <default>
            <some>
                  <random>
                        <xpath>Here is some value.</xpath>
                  </random>
            </some>
      </default>
</config>
11
  • The code seams OK. Make sure you cleared the cache. Better yet, disable it while playing around with Magento. How are you trying to value of the config? Here is the right way to do it: Mage::getStoreConfig('some/random/xpath')
    – Marius
    Commented Apr 8, 2013 at 18:27
  • public function indexAction($coreRoute = null) { echo Mage::getStoreConfig('some/random/xpath'); // Returns nothing var_dump( Mage::getConfig()->getNode('default/some/random/xpath') ); // Returns False die; $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE); if (!Mage::helper('cms/page')->renderPage($this, $pageId)) { $this->_forward('defaultIndex'); } }
    – Chris
    Commented Apr 8, 2013 at 18:56
  • The code above is still not working :(
    – Chris
    Commented Apr 8, 2013 at 19:27
  • try turning off compilation as well in System > Compilation
    – Dan
    Commented Apr 8, 2013 at 20:11
  • Where did you put this code?
    – Marius
    Commented Apr 9, 2013 at 6:37

2 Answers 2

4

All I had to do is re-configure the location of Magento.

System -> Configuration -> General -> (And I set the location to my country Ex. United Kingdom )

At least that's how I managed to get it to work :)

2
  • I don't understand why that works, but it worked for me too! Thanks so much!!! I was developing it fine on my local Bitnami Magento instance, but once I copied it up to the Bitnami Magento instance on EC2, it didn't work there.
    – Adam A
    Commented Apr 4, 2015 at 16:31
  • I don't think you have to re-config location, but just save config once to update cache. Also you might need to re-login if you get 404 message at installed module section.
    – ruuter
    Commented Oct 31, 2015 at 19:06
1

A couple of problems here, firstly you haven't defined the module and version at the top of config.xml, also you should be defining system -> configuration menu items in system.xml rather than config.xml (in the same directory as config.xml). Finally in later versions of Magento you need to define the access control for you module in order for admin to correctly function (this is good practice regardless of Magento version). This can be done inside config.xml, but putting it instead inside adminhtml.xml (again in the same directory as config.xml) keeps things more manageable as config.xml can get pretty long for more complex modules.

The module definition inside app/etc/modules looks fine.

So you would have something like this for your config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <First_Module>
            <version>0.1.0</version>
        </First_Module>
    </modules>
    ...
</config>

And this for your system.xml (defining your system configuration menu items):

<?xml version="1.0"?>
<config>
    <tabs>
        <customtab translate="label">
            <label>Tab Header</label>
            <sort_order>500</sort_order>
        </customtab>
    </tabs>
    <sections>
        <section1 translate="label">
            <label>Section Label</label>
            <tab>customtab</tab>
            <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>
            <groups>
                <optiongroup translate="label">
                    <label>Option Group Header</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>
                        <field1>
                            <label>Field 1 Name</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>
                        </field1>
                        <field2>
                            <label>Field 2 Name</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </field2>
                        <field3>
                            <label>Field 3 Name</label>
                            <frontend_type>hidden</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </field3>
                    </fields>
                </optiongroup>
            </groups>
        </section1>
    </sections>
</config>

Note the above creates a custom tab and has a few example options added.

Finally, your adminhtml.xml defining ACL for your module would be something like this:

<?xml version="1.0"?>
<config>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <section1 module="module">
                                        <title>First Module</title>
                                    </section1>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

With this in place you can then pull these config options using:

Mage::getStoreConfig('section1/optiongroup/field1');
2
  • The module works without the version tag and the config default values can be set in config.xml. Actually that is the only place you can put them. If you have a config setting it is not necessarily to have the system.xml field corresponding to that value. This is needed only if you want to be able to change it.
    – Marius
    Commented Apr 9, 2013 at 11:39
  • A module will in fact work without a config.xml entirely, I know that. Note that the above represents best working practice which especially a new module developer should be following. Also note that the poster did not define whether they needed editable configuration options or just defaults - having editable options is much more regular requirement hence posting the above. Commented Apr 9, 2013 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.