我正在为Magento 1.9.X制作一个模块。但是,我无法创建数据库表grided_products
。我还检查了core_resource
,我的模块也在更新版本。以下是我的代码
config.xml中
<modules>
<Magento_Grided>
<version>0.1.2</version>
</Magento_Grided>
</modules>
<models>
<grided>
<class>Magento_Grided_Model</class>
<resourceModel>grided_resource</resourceModel>
</grided>
<grided_resource>
<entities>
<product>
<table>grided_products</table>
</product>
</entities>
</grided_resource>
</models>
<resources>
<grided_setup>
<setup>
<module>Grided</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</grided_setup>
</resources>
升级-0.1.0-0.1.2.php
<?php
$this->startSetup();
$table = new Varien_Db_Ddl_Table();
$table->setName($this->getTable('grided/product'));
$table->addColumn(
'entity_id',
Varien_Db_Ddl_Table::TYPE_INTEGER,
10,
array(
'auto_increment' => true,
'unsigned' => true,
'nullable'=> false,
'primary' => true
)
);
$table->addColumn(
'created_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
'nullable' => false,
)
);
$table->addColumn(
'updated_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
'nullable' => false,
)
);
$table->addColumn(
'name',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
'nullable' => false,
)
);
$table->setOption('type', 'InnoDB');
$table->setOption('charset', 'utf8');
$this->getConnection()->createTable($table);
$this->endSetup();
型号/ Product.php
<?php
class Magento_Grided_Model_Product extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init('grided/product');
}
}
型号/资源/ Product.php
<?php
class Magento_Grided_Model_Resource_Product extends Mage_Core_Model_Resource_Db_Abstract{
protected function _construct()
{
$this->_init('grided/product', 'entity_id');
}
}
型号/资源/产品/ Collection.php
<?php
class Magento_Grided_Model_Resource_Product_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
protected function _construct()
{
$this->_init('grided/product');
}
}