如果你对JOOMLA有任何问题,请在问答里提交你的问题,将有管理员为你解答!
首页 > 开发手记 > JOOMLA1.6组件开发案例——第一步

JOOMLA1.6组件开发案例——第一步

JOOMLA1.6组件开发案例——第一步

以下开发内容来自官网的开发手册。

我们要做的是建一个其于模块-显示-控制器结构的MVC组件,简单的在前台显示“你好,南荒";

网站目录/components/com_nh/nh.php。

如上所示,在网站目录componetns新建一个目录叫com_nh目录,然后在该目录下在新建一个文件nh.php,包含输出内容:你好南荒,

代码如下:<?php echo "hi,nhuang";?>

我们可以在浏览器输入了"你的网址/index.php?option=com_nh"来测试内空是否有正常显示。

后台显示

 刚刚上面的是前台显示的内容,我们同时还要新建一个后台管理界面。administrator/components/com_nh/nh.php

然后也输入上面的内容。当然随便你输入什么内容都可以,

这个可以在网址/administrator/components/com_nh/nh.php,用浏览器打开测试一下。

安装文件制作

在本地新建一个目录,要你喜欢的编辑器新建以下文件,

以上新建对应目录和文件,最后面的0.0.1.sql是一个空文件,是用来设置这个组件版本的概要。其中几个index.php也是空文件,当用户直接输入这个目录访问时只打开一个空白显示。                          

将上面的文件新建压缩后,在JOOMLA后台安装,你会在后台的组件扩展菜单里发现该组件的身影。当然你也可以直接下载测试,下载地址:

archive下载

自己新建的话,nh.xml包含的安例内容如下:

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.6.0" method="upgrade">

<name>NH南荒</name>
<!-- The following elements are optional and free of formatting conttraints -->
<creationDate>November 2009</creationDate>
<author>John Doe</author>
<authorEmail> 该E-mail地址已受到防止垃圾邮件机器人的保护,您必须启用浏览器的Java Script才能看到。 </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>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>Description of the Hello World component ...</description>

<update> <!-- Runs on update; New in 1.6 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>

<!-- 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>index.html</filename>
<filename>nh.php</filename>
</files>

<administration>
<!-- Administration Menu Section -->
<menu>Hello World!</menu>
<!-- Administration 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 /admin/ in the package -->

<files folder="admin">
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>nh.php</filename>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>

</extension>

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.6.0" method="upgrade">

<name>Hello World!</name>
<!-- The following elements are optional and free of formatting conttraints -->
<creationDate>November 2009</creationDate>
<author>John Doe</author>
<authorEmail> 该E-mail地址已受到防止垃圾邮件机器人的保护,您必须启用浏览器的Java Script才能看到。 </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>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>Description of the Hello World component ...</description>

<update> <!-- Runs on update; New in 1.6 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>

<!-- 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>index.html</filename>
<filename>helloworld.php</filename>
</files>

<administration>
<!-- Administration Menu Section -->
<menu>Hello World!</menu>
<!-- Administration 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 /admin/ in the package -->

<files folder="admin">
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>helloworld.php</filename>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>

</extension>

在两个nh.php文件里输入前面提的内空,当然你也可以输些别的。

index.html 的源代码包含

<html><body bgcolor="#FFFFFF"></body></html>
这样就完成了一个简单的JOOMLA1.6的测试组件,你可以通过网站/index.php?option=com_nh来访问前台内容,如果你是直接下载的那个整装包里,那你就要访问index.php?option=com_helloworld。 最后更新 ( 2011-03-16 13:15 )

Add comment


Security code
Refresh