简体   繁体   English

joomla 2.5在模块install.mysql.utf8.sql中的工作原理

[英]joomla 2.5 in module install.mysql.utf8.sql dosent work

i want to install extranal sql file with module and i follow this link tutorial http://docs.joomla.org/J2.5:Creating_a_simple_module/Using_the_Database but it dose not work. 我想安装带有模块的外部sql文件,我按照此链接教程http://docs.joomla.org/J2.5:Creating_a_simple_module/Using_the_Database进行操作,但它无法正常工作。 here is my xml and sql file coding. 这是我的xml和sql文件编码。 where is my mistake? 我的错误在哪里?

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
<name>practic_module</name>
<author>John Doe</author>
<version>1.0.0</version>
<description>this is a practice module struckture</description>
<files>
<filename>mod_helloworld.xml</filename>
<filename module="mod_helloworld">mod_helloworld.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
    <config>
<install>
    <sql>
     <file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
     <file driver="sqlazure"   charset="utf8">sql/sqlazure/install.sqlazure.utf8.sql</file>
</sql>
</install>

<uninstall>
<sql>
     <file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
     <file driver="sqlazure" charset="utf8">sql/sqlazure/uninstall.sqlazure.utf8.sql</file>
 </sql>
</uninstall>

<update> 
<schemas>
    <schemapath type="mysql">sql/mysql/updates</schemapath> 
    <schemapath type="sqlazure">sql/sqlazure/updates</schemapath> 
</schemas> 
</update>

<fields name="params">
<fieldset name="basic">
    <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM #__helloworld" />
</fieldset>
</fields>


</config>

</extension>

and sql directory is C:\\xampp\\htdocs\\joom\\modules\\mod_helloworld\\sql\\mysql and install.mysql.utf8.sql file is 并且sql目录为C:\\ xampp \\ htdocs \\ joom \\ modules \\ mod_helloworld \\ sql \\ mysql,而install.mysql.utf8.sql文件为

CREATE TABLE IF NOT EXISTS `#__helloworld` (
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `hello` text NOT NULL,
    `lang` varchar(25) NOT NULL,

PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Hello World', 'en-GB');
INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Hola Mundo', 'es-ES');
INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Bonjour tout le monde', 'fr-  FR');  

but it dose not work. 但它不起作用。 database not install. 数据库未安装。 where my mistake? 我的错误在哪里? pls help 请帮助

You have added the <install> , <uninstall> and <update> tags inside the <config> tags which shouldn't be done. 您已经在<config>标记内添加了<install><uninstall><update> <config>标记,这是不应该的。 They need to go outside. 他们需要出去。 You also need to define the sql folder. 您还需要定义sql文件夹。 Here is your full xml code: 这是您的完整xml代码:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
<name>practic_module</name>
<author>John Doe</author>
<version>1.0.0</version>
<description>this is a practice module struckture</description>

<files>
   <filename>mod_helloworld.xml</filename>
   <filename module="mod_helloworld">mod_helloworld.php</filename>
   <filename>index.html</filename>
   <filename>helper.php</filename>
   <filename>tmpl/default.php</filename>
   <filename>tmpl/index.html</filename>
   <folder>sql</folder>
</files>

<install>
    <sql>
     <file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
     <file driver="sqlazure"   charset="utf8">sql/sqlazure/install.sqlazure.utf8.sql</file>
</sql>
</install>

<uninstall>
<sql>
     <file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
     <file driver="sqlazure" charset="utf8">sql/sqlazure/uninstall.sqlazure.utf8.sql</file>
 </sql>
</uninstall>

<update> 
<schemas>
    <schemapath type="mysql">sql/mysql/updates</schemapath> 
    <schemapath type="sqlazure">sql/sqlazure/updates</schemapath> 
</schemas> 
</update>

<config>
   <fields name="params">
      <fieldset name="basic">
         <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM #__helloworld" />
      </fieldset>
   </fields>
</config>

</extension>

Also make sure you folder structure is correct 还要确保您的文件夹结构正确

Hope this helps 希望这可以帮助

I think you should use config tag just around 我认为您应该在周围使用config标签

<fields name="params">
  <fieldset name="basic">
  <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM        #__helloworld" />
  </fieldset>
</fields>

in your uploaded zip, in the manifest file is no <folder>sql</folder> - so the installer dont copy the folder on install into the module directory and dont execute the sql. 在您上传的zip文件中,清单文件中没有<folder>sql</folder> -因此安装程序不会将安装时的文件夹复制到模块目录中,也不会执行sql。

installer: https://github.com/joomla/joomla-cms/blob/master/libraries/cms/installer/installer.php#L912 安装程序: https : //github.com/joomla/joomla-cms/blob/master/libraries/cms/installer/installer.php#L912

You need to include these files in files tag, like this: 您需要在files标记中包含这些文件,如下所示:

<files>
    <!-- The others files that you added -->
    <filename>sql/mysql/install.mysql.utf8.sql</filename>
    <filename>sql/sqlazure/install.sqlazure.utf8.sql</filename>
    <filename>sql/mysql/uninstall.mysql.utf8.sql</filename>
    <filename>sql/sqlazure/uninstall.sqlazure.utf8.sql</filename>
    <filename>sql/sqlazure/updates</filename> <!-- Not sure about this one, sorry -->
</file>

I'm learning too and i don't know if the updates file is necessary to add on files tag. 我也在学习,我不知道是否需要在文件标签上添加更新文件。 Combine this with Lodder's answer. 将其与Lodder的答案结合起来。 Hope be useful. 希望有用。

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

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