Dead Man
Dead Man

Reputation: 2921

Magento - Error in loading model in Magento Extension?

I am developing a magento extension in which i am trying to insert values to a database table, but the problem i am having is that the model is not loading.

The problem is when i am calling save() function in my controller then there comes an error on page which is :

Fatal error: Call to a member function beginTransaction() on a non-object in /var/www/magento/app/code/core/Mage/Core/Model/Abstract.php on line 313 

and when i check for error log in my system.log file then i saw this error :

Warning: include(Gwb/Magecrmsync/Model/Mysql4/Magecrmsync.php): failed to open stream: No such file or directory  in /var/www/magento/lib/Varien/Autoload.php on line 93

I have googled it but couldn't find the answer. Please help

Here's my config.xml code :

<?xml version="1.0"?>
<config>
<!-- turn on our module, required for install support -->
<modules>
<Gwb_Magecrmsync>
    <version>0.1.0</version>
</Gwb_Magecrmsync>
</modules>
<frontend>
<routers>
    <magecrmsync>
        <use>standard</use>
        <args>
            <module>Gwb_Magecrmsync</module>
            <frontName>magecrmsync</frontName>
        </args>
    </magecrmsync>
</routers>
<layout>
    <updates>
        <magecrmsync>
            <file>adminhtml.xml</file>
        </magecrmsync>
    </updates>
</layout>
</frontend>
<admin>
<routers>
    <magecrmsync>
        <use>admin</use>
        <args>
            <module>Gwb_Magecrmsync</module>
            <frontName>magecrmsync</frontName>
        </args>
    </magecrmsync>
</routers>
</admin>
<adminhtml>
<menu>
    <menu1 translate="title" module="magecrmsync">
        <title>Synchronize</title>
        <sort_order>999</sort_order>
        <children>
            <menuitem1 module="magecrmsync">
                <title>Customers</title>
                <action>magecrmsync/adminhtml_customers</action>
            </menuitem1>
            <menuitem2 module="magecrmsync">
                <title>Orders</title>
                <action>magecrmsync/adminhtml_orders</action>
            </menuitem2>
            <menuitem3 module="magecrmsync">
                <title>Products</title>
                <action>magecrmsync/adminhtml_products</action>
            </menuitem3>
            <menuitem4 module="magecrmsync">
                <title>Settings</title>
                <action>magecrmsync/adminhtml_settings</action>
            </menuitem4>
        </children>
    </menu1>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <menu1 translate="title" module="magecrmsync">
                    <title>Synchronize</title>
                    <sort_order>999</sort_order>
                    <children>
                        <menuitem1>
                            <title>Customers</title>
                        </menuitem1>
                        <menuitem2>
                            <title>Orders</title>
                        </menuitem2>
                        <menuitem3>
                            <title>Products</title>
                        </menuitem3>
                        <menuitem4>
                            <title>Settings</title>
                        </menuitem4>
                    </children>
                </menu1>
            </children>
        </admin>
    </resources>
</acl>
</adminhtml>
<global>
<!-- turn on models -->
<models>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Model</class>
        <resourceModel>Magecrmsync_mysql4</resourceModel>
    </magecrmsync>
    <Magecrmsync_mysql4>
        <class>Gwb_Magecrmsync_Model_Mysql4</class>
        <entities>
            <magecrmsync>
                <table>magecrmsync</table>
            </magecrmsync>
        </entities>
    </Magecrmsync_mysql4>
</models>
<!-- turn on models -->

<!-- turn on database connections -->
<resources>
<!-- setup is needed for automatic installation -->
    <magecrmsync_setup>
        <setup>
            <module>Gwb_Magecrmsync</module>
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </magecrmsync_setup>
    <magecrmsync_write>
        <connection>
            <use>core_write</use>
        </connection>
    </magecrmsync_write>
    <magecrmsync_read>
        <connection>
            <use>core_read</use>
        </connection>
    </magecrmsync_read>
</resources>

<blocks>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Block</class>
    </magecrmsync>
</blocks>

<helpers>
    <magecrmsync>
        <class>Gwb_Magecrmsync_Helper</class>
    </magecrmsync>
</helpers>

<layout>
    <magecrmsync>
        <file>adminhtml.xml</file>
    </magecrmsync>
</layout>

</global>
</config>

Here's my function in my controller file :

public function settingsAction()
{
    if($this->getRequest()->getPost())
    {
        try
        {
            $login_info = Mage::getModel('magecrmsync/magecrmsync');
            $username = $this->getRequest()->getPost('username');
            $password = $this->getRequest()->getPost('password');

            $login_info->setUsername($username);
            $login_info->setPassword(md5($password));
            $login_info->save();

            Mage::getSingleton('adminhtml/session')->addSuccess("Login Information has been updated successfully.");                
        }
        catch(Exception $e)
        {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
    else
    {
        Mage::getSingleton('adminhtml/session')->addError("Error! Please try again.");
    }
    $this->_redirect('/*/*');
}

Can anyone identify the problem here which is not letting my model to load?

Any help would be appreciated and will be helpful to me.

Thanks in advance

Upvotes: 4

Views: 7160

Answers (2)

Dead Man
Dead Man

Reputation: 2921

After researching for more than 24 hours, i finally got it to work. I was having this error (File Not Found) because of folder permissions. When i gave the permission to the folder it worked. Thanks for helping me.

Upvotes: 4

Fabian Schmengler
Fabian Schmengler

Reputation: 24551

Magento tries to load your file from Mage/Magecrmsync/Mysql4/Model/Magecrmsync.php, this means it interpretes the alias 'magecrmsync/magecrmsync' for your resource model as Mage_Magecrmsync_Mysql4_Model_Magecrmsync. Let's have a look, how you configured your resource model alias:

    <resourceModel>Magecrmsync_mysql4</resourceModel>

And then:

<magecrmsync_mysql4>

The element names are case sensitive, so Magento does not find it and interpretes it as a class alias with the default namespace Mage.

Upvotes: 0

Related Questions