除了faq_question,faq_answer之外,Magento set函数不适用于任何其他列。 主键只是继续递增,但数据没有插入列中。
无论我给列名称赋予什么名称,但它只是继续显示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();
}
}
数据库表
答案 0 :(得分:3)
如果运行SQL安装脚本后Magento模型似乎无法正常工作,例如一个模型没有将值保存到由SQL脚本明确添加的字段中,那么你很可能被Magento的DDL缓存所困。
除了其他内容(例如CREATE
,INDEX
和FOREIGN KEY
语句)之外,Magento还会缓存耗时DESCRIBE table
语句的结果。然后,Magento模型使用此类缓存结果(例如,在保存时)以获得更好的性能。
现在,如果出于某种原因,在运行更改表格方案(ALTER, ADD, DROP
)的SQL脚本后,您的系统无法更新此DDL缓存,则您的模型仍将使用旧缓存,而不知道任何更改。< / p>
不幸的是,Magento Admin后端中的清除缓存按钮/链接的 none 允许您按需清除DDL缓存。无论是明确的还是含蓄的(至少是afaik,如果我错了,请纠正我)。
要清除DDL缓存,您可以使用瑞士军刀方法,只需手动删除var/cache/*
文件夹即可。请注意,这将清除所有现有Magento的缓存,而不仅仅是DDL缓存。
或者您可以致电Varien_Db_Adapter_Pdo_Mysql::resetDdlCache()
或其众多衍生品之一,例如Mage_Core_Model_Resource_Setup::getConnection()->resetDdlCache()
。
resetDdlCache()
方法允许您为单个表重置DDL高速缓存,或者同时为所有表重置DDL高速缓存。但请注意,它取决于_isDdlCacheAllowed
属性的当前状态,是否将处理重置。