4

我正在开发一个 magento 扩展,我试图将值插入到数据库表中,但我遇到的问题是模型没有加载。

问题是当我save()在控制器中调用函数时,页面上出现错误:

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 

当我检查system.log文件中的错误日志时,我看到了这个错误:

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

我用谷歌搜索了它,但找不到答案。请帮忙

这是我的config.xml代码:

<?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>

这是我的控制器文件中的函数:

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('/*/*');
}

谁能确定这里没有让我的模型加载的问题?

任何帮助将不胜感激,并将对我有所帮助。

提前致谢

4

2 回答 2

4

经过24个多小时的研究,我终于让它工作了。由于文件夹权限,我遇到了这个错误(找不到文件)。当我授予它工作的文件夹的权限时。谢谢你帮助我。

于 2013-03-12T11:50:16.913 回答
0

Magento 尝试从 加载您的文件,这意味着它将您的资源模型Mage/Magecrmsync/Mysql4/Model/Magecrmsync.php的别名解释为. 让我们看看,您是如何配置资源模型别名的:'magecrmsync/magecrmsync'Mage_Magecrmsync_Mysql4_Model_Magecrmsync

    <resourceModel>Magecrmsync_mysql4</resourceModel>

进而:

<magecrmsync_mysql4>

元素名称区分大小写,因此 Magento 找不到它并将其解释为具有默认命名空间的类别名Mage

于 2013-03-12T09:48:56.550 回答