2013-02-01 91 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/ –

相关问题