Magento set函数对除faq_question、faq_answer之外的任何其他列都不起作用。主键继续递增,但是数据没有插入到列中。
不管我给列名起了什么名字,但它还是一直显示为null。奇怪的是,如果我手动填充字段并使用getFaqJugaad(),它就能正常工作。我可以从数据库中获取这些值。但未设置请帮助。谢谢
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Gagan_Faq>
<version>0.2.0</version>
</Gagan_Faq>
</modules>
<frontend>
<routers>
<faq>
<use>standard</use>
<args>
<module>Gagan_Faq</module>
<frontName>faq</frontName>
</args>
</faq>
</routers>
<layout>
<updates>
<faq>
<file>gaganfaq.xml</file>
</faq>
</updates>
</layout>
</frontend>
<global>
<blocks>
<faq>
<class>Gagan_Faq_Block</class>
</faq>
</blocks>
<helpers>
<faq>
<class>Gagan_Faq_Helper</class>
</faq>
</helpers>
<models>
<faq>
<class>Gagan_Faq_Model</class>
<resourceModel>faq_mysql4</resourceModel>
</faq>
<faq_mysql4>
<class>Gagan_Faq_Model_Mysql4</class>
<entities>
<dinkchika>
<table>gagan_faq</table>
</dinkchika>
<dinkchika02>
<table>gagan_faq_creation</table>
</dinkchika02>
</entities>
</faq_mysql4>
</models>
<resources>
<faq_setup>
<setup>
<module>Gagan_Faq</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</faq_setup>
<faq_write>
<connection>
<use>core_write</use>
</connection>
</faq_write>
<faq_read>
<connection>
<use>core_read</use>
</connection>
</faq_read>
</resources>
</global>
这是我的安装脚本
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE IF NOT EXISTS {$this->getTable('faq/dinkchika')} (
`faq_id` int(11) NOT NULL AUTO_INCREMENT,
`faq_question` varchar(255) DEFAULT NULL,
`faq_answer` varchar(255) DEFAULT NULL,
`faq_jugaad` varchar(255) DEFAULT NULL,
PRIMARY KEY (`faq_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();indexController
<?php
class Gagan_Faq_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$mod = Mage::getModel('faq/faq');
$mod->setFaqQuestion('how are 5454you?');
$mod->setFaqAnswer('gooddsfsfsdfsfdffsd?');
$mod->setFaqJugaad('sfsfdsfsfsdfsfdffsd?');
$mod->save();
$this->renderLayout();
}
}数据库表

发布于 2013-03-15 19:23:13
如果Magento模型在运行SQL设置脚本后似乎不能正常工作,例如,一个模型没有将值保存到SQL脚本明确添加的字段中,那么您很可能被Magento的DDL缓存所捕获。
除了其他东西(如CREATE、INDEX和FOREIGN KEY语句),Magento还缓存耗时的DESCRIBE table语句的结果。Magento模型然后使用这些缓存的结果(例如,在保存时)以获得更好的性能。
现在,如果由于任何原因,您的系统在运行更改表方案(ALTER, ADD, DROP)的SQL脚本后无法更新此DDL缓存,您的模型将仍然使用旧的缓存,而不知道任何更改。
不幸的是,Magento Admin后端中的清除缓存按钮/链接都不允许您按需清除DDL缓存。既不明确也不隐含(至少afaik,如果我错了,请纠正我)。
清除DDL缓存
要清除DDL缓存,您可以使用瑞士军刀方法并简单地手动删除您的var/cache/*文件夹。请注意,这将清除所有现有的Magento缓存,而不仅仅是DDL缓存。
或者,您可以调用Varien_Db_Adapter_Pdo_Mysql::resetDdlCache()或其众多派生函数之一,例如Mage_Core_Model_Resource_Setup::getConnection()->resetDdlCache()。
resetDdlCache()方法允许您重置单个表的DDL缓存,或者一次重置所有表的DDL缓存。但请注意,这取决于_isDdlCacheAllowed属性的当前状态,即是否将处理重置。
https://stackoverflow.com/questions/15378141
复制相似问题