Итак, давайте создадим самый простой и любимый уже всем компонент Hello World! или Привет МИР!
Интерфейс пользователя
Для начала создайте у себя на компьютере папку com_helloworld , в ней создайте папку site
Далее создайте файл helloworld.php со следующим содержимым:
Привет МИР!!!
при этом кодировка файла должна быть UTF-8. Сохраните этот файл в папку site
Интерфейс администратора
В папке com_helloworld создайте еще одну папку и назовите ее admin
Далее создайте файл helloworld.php со следующим содержимым:
Привет МИР! Администратор
кодировка файла должна быть так же, хотя и всех других файлов тоже, UTF-8. Сохраните этот файл в папку admin .
Далее создадим установочный файл для нашего компонента. Для этого откройте текстовый редактор и вставьте следующий код:
<?xml version="1.0" encoding="utf-8"?> <extension type="component" version="2.5.0" method="upgrade"> <name>com_helloworld</name> <!-- The following elements are optional and free of formatting constraints --> <creationDate>Март 2012</creationDate> <author>Имя автора</author> <authorEmail>автор@домен.рф</authorEmail> <authorUrl>http://домен.рф</authorUrl> <copyright>Copyright Info</copyright> <license>Лицензия</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> <update> <!-- Runs on update; New in 2.5 --> <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>Привет МИР!</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>
Сохраните этот файл в папке com_helloworld под именем helloworld.xml .
Далее в папке admin создайте следующую структуру папок:
Создайте пустой файл и сохраните его в следующей папке admin\sql\updates\mysql\ под именем 0.0.1.sql .
И наконец создайте файл со следующим содержимым:
<html><body bgcolor="#FFFFFF"></body></html>
и сохраните его во все папки нашего компонента.
В папке com_helloworld у вас должна получиться следующая структура:
- helloworld.xml
- site/helloworld.php
- site/index.html
- admin/index.html
- admin/helloworld.php
- admin/sql/index.html
- admin/sql/updates/index.html
- admin/sql/updates/mysql/index.html
- admin/sql/updates/mysql/0.0.1.sql
Теперь создайте zip архив компонента поместив в него выше перечисленные файлы и папки, назовите его com_helloworld.zip .
Откройте сайт, зайдите в панель администратора и установите компонент.
В пункте меню «Компоненты» появится ссылка на наш компонент, пройдя по которой мы увидим наш текст.
Также работу нашего компонента мы можем увидеть и в интерфейсе пользователя для этого откройте следующий адрес: вашдомен.ру/index.php?option=com_helloworld
На этом пока все. Удачи!