如何在magento中为自定义模块创建表?

VIV*_*MDU 1 magento magento-1.7

我是magento的新人.我需要在Magento中创建自己的模块(或)扩展.在我的模块中,无法在magento表中创建表.我正在使用此代码.

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();
Run Code Online (Sandbox Code Playgroud)

然后,可以像这样调用config.xml文件,

<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>
Run Code Online (Sandbox Code Playgroud)

我在管理面板中创建选项卡,前端块已创建,但我无法为自定义模块创建表.如何为我的自定义模块创建表?

任何帮助,将不胜感激.

fre*_*nto 5

将资源部分添加到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>
Run Code Online (Sandbox Code Playgroud)

  • 我将参考此链接创建模块.... http://www.amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento/ (2认同)