简体   繁体   English

如何在magento的自定义模块中创建sql安装程序以通过脚本创建表

[英]how to create sql installer in custom module in magento for creating table by script

i need to create sql installer in magento.....i created a module and i created table by sql query directly to sql editor... 我需要在magento中创建sql安装程序.....我创建了一个模块,并通过sql查询直接向sql编辑器创建了表...

but for global module i need to create sql installer...in magento sql... im giving my config detail....and also i want to know that what changes in necessary for executing sql script in magento ...also i want to know that what should in sql script. 但对于全局模块,我需要在magento sql中创建sql安装程序...即时通讯给我我的配置详细信息...想知道在sql脚本中应该做什么。

my config.. 我的配置

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <!-- module configuration -->
    <modules>
        <Webcreon_Seller>
            <version>0.0.1</version>
        </Webcreon_Seller>
    </modules>
    <!-- module configuration end -->
    <frontend>
        <routers>
            <seller>
                <use>standard</use>
                <args>
                    <module>Webcreon_Seller</module>
                    <frontName>seller</frontName>  
                </args>
            </seller>
        </routers>
     <layout>
            <updates>
                <seller>
                      <file>sellerform.xml</file>
                </seller>
            </updates>
       </layout>
    </frontend>
    <admin>
     <routers>
         <seller>
            <use>admin</use>
            <args>
               <module>Webcreon_Seller</module>
               <frontName>adminseller</frontName>
            </args>
         </seller>
      </routers>
 </admin>
 <adminhtml>
   <layout>
      <updates>
          <seller>
              <file>sellerform.xml</file>
           </seller>
      </updates>
   </layout>
   <menu>
      <customer translate="title" module="adminhtml">

         <sort_order>10</sort_order>
         <children>
             <set_time>
                   <title>Seller List</title>
                   <action>adminseller/adminhtml_index</action>
              </set_time>
          </children>
       </customer>
    </menu>
</adminhtml> 

    <global>
        <blocks>
            <seller>
                <class>Webcreon_Seller_Block</class>
            </seller>
         </blocks>
         <helpers>
            <seller>
                <class>Webcreon_Seller_Helper</class>
            </seller> 
        </helpers>
              <models>
          <seller>
                <class>Webcreon_Seller_Model</class>
                 <resourceModel>seller_mysql4</resourceModel>
            </seller> 
            <seller_mysql4>
             <class>Webcreon_Seller_Model_Mysql4</class>
             <entities>
                 <seller>
                   <table>db_vendor</table>
                 </seller>
              </entities>
          </seller_mysql4>
        </models>
        <resources>
        <!-- connection to write -->
        <seller_write>
            <connection>
                <use>core_write</use>
            </connection>
        </seller_write>
        <!-- connection to read -->
       <seller_read>
          <connection>
             <use>core_read</use>
          </connection>
       </seller_read>
</resources>
    </global>


</config>

In your config file under "resources" tag add the following above 在您的配置文件中“资源”标签下,添加以下内容

<seller_setup>
    <setup>
         <module>Webcreon_Seller</module>
    </setup>
    <connection>
      <use>core_setup</use>
    </connection>
 </seller_setup>

Now create the folder named "sql" inside your module.And create folder named "seller_setup" inside sql folder. 现在,在模块内创建名为“ sql”的文件夹。并在sql文件夹内创建名为“ seller_setup”的文件夹。 Inside that create a php file named "mysql4-install-0.1.0.php". 在其中创建一个名为“ mysql4-install-0.1.0.php”的php文件。 Remember one thing that in this filename 0.1.0 should match the module version that you defined in config.xml at the top. 记住一件事,该文件名0.1.0应该与您在顶部config.xml中定义的模块版本匹配。 In your case it is ok. 您的情况还可以。 Now inside that create your table with the fields. 现在,在其中创建带有字段的表。 I have provided an example below.Edit as your requirement. 我在下面提供了一个示例。根据您的要求进行编辑。

     <?php

$installer = $this;

$installer->startSetup();

$installer->run("
DROP TABLE IF EXISTS {$this->getTable('vendor_profile')};
CREATE TABLE {$this->getTable('vendor_profile')} (
  `vendor_profile_id` int(11) unsigned NOT NULL auto_increment,
  `vendor_id` int(11) unsigned NOT NULL,
  `discipline` varchar(255) NULL default '',
  `studio_title` varchar(255) NULL default '',
  `profilepic`  varchar(255) NULL ,
  `bannerpic`  varchar(255) NULL ,
  `biography` TEXT NOT NULL default '',
  `facebookid` varchar(255) NOT NULL default '',
  `twitterid` varchar(255) NOT NULL default '',



PRIMARY KEY (`vendor_profile_id`),FOREIGN KEY(vendor_id) REFERENCES udropship_vendor(vendor_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");

$installer->endSetup();

Now after everything is set up refresh your web page and see your database you will see your table. 现在,一切设置完成后,刷新您的网页并查看数据库,您将看到表格。 For upgrade script refer to magento commerce wiki. 有关升级脚本,请参阅magento Commerce Wiki。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM