一 初級HelloWorld
組建是放在components目錄下面的。
1、我們可以在Joomla根目錄下直接建立一個目錄com_helloworld
注意:組建目錄都是以com_開頭的。
2、在com_helloworld目錄下建立 helloworld.php
注意:命名要和目錄名一致!
helloworld.php 內容:
hello world
測試:
http://localhost/index.php?option=com_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,已經可以安裝了。
在後台安裝該組件。後台組件裡面就可以看到這個組件了。
開啟之後:
前台測試:http://localhost/administrator/index.php?option=com_helloworld