我正在开发一个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('/*/*');
}
任何人都可以在这里找出不让我的模型加载的问题吗?
任何帮助都将受到赞赏,对我有所帮助。
提前致谢
答案 0 :(得分:4)
经过超过24小时的研究,我终于开始工作了。由于文件夹权限,我遇到此错误(找不到文件)。当我授予它工作的文件夹的权限。谢谢你的帮助。
答案 1 :(得分:0)
Magento尝试从Mage/Magecrmsync/Mysql4/Model/Magecrmsync.php
加载您的文件,这意味着它会将资源模型的别名'magecrmsync/magecrmsync'
解释为Mage_Magecrmsync_Mysql4_Model_Magecrmsync
。我们来看看如何配置资源模型别名:
<resourceModel>Magecrmsync_mysql4</resourceModel>
然后:
<magecrmsync_mysql4>
元素名称区分大小写,因此Magento找不到它并将其解释为具有默认命名空间Mage
的类别名。