php - Magento - 在 Magento 扩展中加载模型时出错?

标签 php magento

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

问题是当我在 Controller 中调用 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>

这是我的 Controller 文件中的函数:

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

谁能找出我的模型无法加载的问题?

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

提前致谢

最佳答案

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

关于php - Magento - 在 Magento 扩展中加载模型时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15353888/

相关文章:

php - 如何使用数组中的项目创建连续播放?

php - 为什么我的重写规则会禁用额外的 $_GET 数据?

php - 如何在 Symfony2 中用 Doctrine2 生成的实体指定 setter 名称?

javascript - 如何将我的 HTML 表单提交与我的 JavaScript 表单更新分开?

mysql - 在magento 1.8.0.0版本中运行mysql复杂查询

ajax - 玛根托 |在类别页面和产品 View 上使用数量增量和 ajax 添加到购物车

php - 使用外部链接 PHP 的 readfile() 进行可恢复下载

image - 如何在 TCPDF 中添加图像

php - 如何使用 composer 安装 Magento2 示例模块?

php - 从 Magento 中的脚本保存具有分层定价的产品模型时的奇怪行为