Joomla文档中文翻译 - MVC组件开发:数据库 - 更新安装文件

thumb-joomla-doc-viiiix在昨天的文档中,我们学习了怎样为组件创建用于安装和卸载的SQL文件;今天我们来看看怎样在组件的安装文件install.xml文件中做相应的修改,将之前的SQL文件信息包含进来。

我们需要做三件事情:首先将两个新创建的SQL文件放到file列表中声明然后将SQL文件列表放到用于声明admin文件的路径中,最后我们要告诉安装器在安装或卸载的过程中执行查询变量。

光说不练嘴把式,光练不说傻把式;下面我们来看看实际的代码,然后稍作解释:

<?xml version="1.0" encoding="utf-8"?>
<install type="component" version="1.5.0">
<name>Hello</name>
<!-- The following elements are optional and free of formatting conttraints -->
<creationDate>2007-02-22</creationDate>
<author>John Doe</author>
<authorEmail> This e-mail address is being protected from spambots. You need JavaScript enabled to view it </authorEmail>
<authorUrl>http://www.example.org</authorUrl>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<!-- The version string is recorded in the components table -->
<version>3.01</version>
<!-- The description is optional and defaults to the name -->
<description>Description of the component ...</description>

<!-- Site Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
<files folder="site">
<filename>controller.php</filename>
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>models/hello.php</filename>
<filename>models/index.html</filename>
<filename>views/index.html</filename>
<filename>views/hello/index.html</filename>
<filename>views/hello/view.html.php</filename>
<filename>views/hello/tmpl/default.php</filename>
<filename>views/hello/tmpl/index.html</filename>
</files>

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

<administration>
<!-- Administration Menu Section -->
<menu>Hello World!</menu>

<!-- Administration Main File Copy Section -->
<files folder="admin">
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>install.sql</filename>
<filename>uninstall.sql</filename>
</files>

</administration>
</install>

我们之前所述的三个步骤在代码中的顺序大致是相反的;可以看到,在代码靠下的地方,我们将两个SQL文件放在了<administration>容器里面的<files folder="admin">...</files>标签中,用来进行声明。

在<install>和<uninstall>标签中,用来声明SQL文件的<file>标签有两个属性,charset和driver;charset用来声明字符集,我们在这里使用utf-8,对应着数据表的默认编码;driver属性用来指定查询参数是通过什么数据库来执行的,我们将其设置为“mysql”即可;安装文件就这样被搞定了。

目前为止,我们的组件本身已经基本完成,包括了MVC的各个部分以及数据库文件;接下来将进入该文档系列的第四部分,我们会了解到怎样为组件创建后台管理界面。

  • Joomla文档中文翻译 - MVC组件开发:基础
  • Joomla文档中文翻译 - MVC组件开发:创建模型及相关扩展
  • Joomla文档中文翻译 - MVC组件开发:使用数据库
  • Joomla文档中文翻译 - MVC组件开发:创建后台管理界面
  • Joomla文档中文翻译 - MVC组件开发:后台基本框架
  • Joomla文档中文翻译 - MVC组件开发:添加后台行为

译者:Viiiix7210

如需转载,请注明官方英文文档及本人译文的出处,谢谢。查看官方英文文档: Developing a Model-View-Controller Component - Part 3 - Using the Database


收藏与分享

添加评论


Security code
换一张图