0

I have created a custom module using the atwix tutorial: http://www.atwix.com/magento/adding-custom-attribute-to-a-cms-page/

but I cannot save the data entered into the custom module from the cms into the database. I flushed the cache because I read that can help but it doesn't make a difference.

I also checked my database in phpmyadmin and can see that the query isn't being executed. I think the main reason for this is because I am having problems creating my own installer script. I saw the tutorial on the Magento website but it didn't work even though I followed it. I don't understand what I'm doing wrong and after pulling my hair out for 3 days I need help.

I have attached a screenshot of my files and the file structure:

file structure

Here is the code from my config.xl file:

<?xml version="1.0"?>
<config>
    <modules>
        <Aa_Custom>
            <version>0.1.0</version>
        </Aa_Custom>
    </modules>
    <global>
        <models>
            <aacustom>
                <class>Aa_Custom_Model</class>
            </aacustom>
        </models>
        <events>
            <adminhtml_cms_page_edit_tab_content_prepare_form>
                <observers>
                    <aa_page_edit_tab_content>
                        <type>singleton</type>
                        <class>Aa_Custom_Model_Observer</class>
                        <method>cmsField</method>
                    </aa_page_edit_tab_content>
                </observers>
            </adminhtml_cms_page_edit_tab_content_prepare_form>
        </events>
        <page>
            <layouts>
                <aa_custom_page>
                    <label>Aa Custom Page</label>
                    <template>page/aa-page.phtml</template>
                </aa_custom_page>
            </layouts>
        </page>
    </global>
</config>
  • Well your install script is in the wrong location for a start, but to help we need to see your config.xml, can you add that to the question? – Jonathan Hussey Oct 24 '14 at 8:32
  • Your install script should be in an "aa_custom_setup" folder within "sql" - ensure your version number in config.xml is equal to, if not higher than the version number in the filename of the install script. – Douglas Radburn Oct 24 '14 at 9:00
  • This may not actually be the case, the folder install scripts need to reside in is defined by the config.xml so although standard practice is to use module_setup for core modules (or namespace_module_setup for EE modules) it can in reality be anything you like. – Jonathan Hussey Oct 24 '14 at 9:19
  • Thanks @JonathanHussey. I have added the code from my config.xml file in my question. – fnk Oct 24 '14 at 9:35
0

The setup script is not running because you have not defined this resource in your config.xml. You need to include:

...
<global>
    ...
    <resources>
        <custom_setup>
            <setup>
                <module>Aa_Custom</module>
                <class>Mage_Catalog_Model_Resource_Setup</class> <!-- depending on setup script content this may not be needed -->
            </setup>
        </custom_setup>
    </resources>
</global>
...

The node <custom_setup> defines the location the script should reside under the sql directory, so in this example you need to put your script in a custom_setup subdirectory of the sql directory. As a side note depending on Magento version (1.6CE onwards) you may also want to switch to the new style setup script which is just named install-0.1.0.php.

  • I tried this @JonathanHussey but it is still not working, once again nothing in the database and it looks like the installer script isn't working. – fnk Oct 24 '14 at 10:18
  • Ok well I can assure you the above is correct so clear your config cache (even if it's disabled) and check there are no errors in the script in which case it won't run. Also check the core_resource database table for an entry where the code column is custom_setup. If it exists delete the row and the script will re-run. – Jonathan Hussey Oct 24 '14 at 10:24
  • Thank you for your help @Jonathan, I cleared my cache for the millionth time and deleted the row in the code_resource table in the database and when I went back to the cms it worked! It saved my data! The only thing is I need more than 1 custom module for the pages. Do I just repeat the process for the next one or is there a better way of adding more custom fields in the backend? – fnk Oct 24 '14 at 10:41
  • Great, glad it worked. If you want to make further changes to the database you can continue adding scripts at the same time incrementing your module version in config.xml. So if you change the module version to 0.1.1 you can add the upgrade script upgrade-0.1.0-0.1.1.php and Magento will run the upgrade script in the same way as the initial install script. Bear in mind if you remove the row from the core_resource table again all install scripts will run, you can also just edit the version shown here to run just some scripts again, so setting 0.1.0 will cause the second one to run – Jonathan Hussey Oct 24 '14 at 10:50
  • I'm not quite sure I understand. Changing the version number and adding the upgrade script I get. What I want is to add another field in the cms. Does that mean I only need to edit the observer file? What I'm asking is how do I add multiple modules? Thanks. – fnk Oct 24 '14 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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