如何在magento中为自定义模块创建表? [英] How to create table for custom module in magento?
本文介绍了如何在magento中为自定义模块创建表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是magento的新手.我需要在Magento中创建自己的模块(或)扩展.在我的模块中,无法在magento表中创建表.我正在使用此代码.
I am new in magento. I need to create my own module (or) extension in Magento. In my module, table cannot be created in the magento table. I am using this code.
File:/app/code/local/com_name/module_name/sql/module_setup/mysql4_install-0.1.0.php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {$this->getTable('th_tweet')};
CREATE TABLE {$this->getTable('th_tweet')} (
`tweet_id` int(11) NOT NULL AUTO_INCREMENT,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`twitter_id` bigint(20) NOT NULL,
`text` text NOT NULL,
PRIMARY KEY (`tweet_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
");
$installer->endSetup();
然后,可以这样调用config.xml文件
then, config.xml file can be called like this,
<models>
<tweet>
<class>TechAndHouse_Tweet_Model</class>
<resourceModel>tweet_mysql4</resourceModel>
</tweet>
<tweet_mysql4>
<class>TechAndHouse_Tweet_Model_Mysql4</class>
<entities>
<tweet>
<table>th_tweet</table>
</tweet>
</entities>
</tweet_mysql4>
</models>
我正在管理面板中创建选项卡,并且创建了前端块,但无法为自定义模块创建表. 如何为我的自定义模块创建表?
I was creating tabs in admin panel and the front end block was createded but i can not create a table for my custom module. How to create a table for my custom module?
任何帮助将不胜感激.
推荐答案
将资源部分添加到全局config.xml中
Add resources section to your config.xml, global
<global>
...
<resources>
<tweet_setup>
<setup>
<module>TechAndHouse_Tweet</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</tweet_setup>
<tweet_write>
<connection>
<use>core_write</use>
</connection>
</tweet_write>
<tweet_read>
<connection>
<use>core_read</use>
</connection>
</tweet_read>
</resources>
...
</global>
这篇关于如何在magento中为自定义模块创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文