我想安装带有模块的external sql文件,并遵循此链接教程http://docs.joomla.org/J2.5:Creating_a_simple_module/Using_the_Database但它不起作用。这是我的xml和sql文件编码。我的错在哪里?
<?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>
sql目录为C:''examplep''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');
但它不起作用。数据库未安装。我的错在哪里?请帮助
您已经在<config>
标记中添加了<install>
、<uninstall>
和<update>
标记,这是不应该做的。他们需要到外面去。您还需要定义sql文件夹。这是您的完整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>
还要确保你的文件夹结构是正确的
希望这能帮助
我认为您应该在周围使用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>
在上传的zip中,清单文件中没有<folder>sql</folder>
,因此安装程序不会在安装时将文件夹复制到模块目录中,也不会执行sql。
安装程序:https://github.com/joomla/joomla-cms/blob/master/libraries/cms/installer/installer.php#L912
您需要将这些文件包含在文件标签中,如下所示:
<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>
我也在学习,我不知道更新文件是否有必要添加到文件标签上。将此与Lodder的回答结合起来。希望有用。