Joomla2.5 Component 组件开发入门之HelloWorld 详解

Joomla2.5 Component 组件开发入门之HelloWorld 详解!

一  初级HelloWorld

组建是放在components目录下面的。

1、我们可以在Joomla根目录下直接新建一个目录com_helloworld

注意:组建目录都是以com_开头的。

2、在com_helloworld目录下新建 helloworld.php  

注意:命名要和目录名一致!

helloworld.php 内容:

hello world



测试:

http://localhost/index.php?option=com_helloworld

Joomla2.5  Component 组件开发入门之HelloWorld 详解

这个错误是正常的,因为我们没有安装正规的方法来。

继续看下面

二、helloworld之完善

用正规的方法,来开发一个可安装的组件,ZIP压缩文件!

重新在外面另建一个文件夹com_helloworld

在此文件夹下新建:

site/helloworld.php  (前台)

site/index.html (前台)

admin/helloworld.php (后台)

admin/index.html (后台)

hellowold.xml (安装该组件的一些配置信息)

下面来介绍各文件的内容:

site/helloworld.php

Hello world


admin/helloworld.php:

Hello World Administrator
hellowold.xml

<?xml version="1.0" encoding="utf-8"?>
<install type="component" version="2.5">
<name>helloworld</name>
<creationDate>2011-11-09</creationDate>
<author>gao tong</author>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<version>1.01</version>
<description>Hello World Test Component ...</description>

<files folder="site">
<filename>index.html</filename>
<filename>helloworld.php</filename>
</files>


<administration>
<menu img="components/com_proforms/images/love.png" >COM_HelloWorld</menu>
<files folder="admin">
<filename>index.html</filename>
<filename>helloworld.php</filename>
</files>
</administration>

</install>

上面的配置比较的重要的就是 指定所有的文件,要正确!

<administration>必须要有,组件的安装是前台和后台都要有的


index.html

可以留空!或:

<html><body bgcolor="#FFFFFF"></body></html>


最后:打包成ZIP,已经可以安装了。

在后台安装该组件。后台组件里面就可以看到这个组件了。

打开之后:

Joomla2.5  Component 组件开发入门之HelloWorld 详解
前台测试:http://localhost/administrator/index.php?option=com_helloworld

Joomla2.5  Component 组件开发入门之HelloWorld 详解