2013-02-01 89 views
1

我是新的magento。我需要在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(); 

然後,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> 

我創建的管理面板和標籤前端塊createded,但我不能爲我的自定義創建表模塊。 如何爲我的自定義模塊創建表格?

任何幫助,將不勝感激。

回答

5

添加資源部分,將config.xml中,全球

<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> 
+1

感謝ü@ magalter..i把我的config.xml中file..but 404錯誤的前端和無表數據庫中創建... –

+2

我會參考這個鏈接創建模塊.... http://www.amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento/ –

相關問題