Печать

Создаём компонент в Joomla 2.5. Часть 1.

Что такое компонент Joomla?

Компонентом в Joomla называется самое важное расширение, имеющее наибольшую функциональность. Компоненты бывают двух типов:

  1. Компоненты ядра Joomla, которые доступны сразу после установки.
  2. Самостоятельные приложения, расширяющие функциональность сайта.

Компоненты могут взаимодействовать с модулями Joomla и плагинами Joomla, которые значительно влияют на способы вывода содержимого компонентов Joomla.

 Не будем нарушать традиции программистов и создадим первый самый простой компонент Hello World, который, как вы уже догадались, будет приветствовать вселенную.

Для этого используя свои любимые инструменты разработчика создайте файл /yoursite/components/com_helloworld/helloworld.php содержащим

Hello world

А теперь протестируем этот базовый компонент вставив index.php?option=com_helloworld в адресную строку браузера.

Далее аналогично только для файла yoursite/administrator/components/com_helloworld/helloworld.php содержащим

Hello world administration

Протестировать его можно вставив administrator/index.php?option=com_helloworld в адресную строку браузера.

Cобираем установочный zip-file.

Используя Joomla вы замечали, что расширения устанавливаются с помощью сжатого файла, содержащим все, что необходимо для установки и удаления расширения.
Теперь с помощью файлового менеджера создайте директорию содержащую

  • 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


admin/sql/updates/mysql/0.0.1.sql — сейчас пустой файл, а так обычно служит для инициализации sql-схемы для компонентов.
Сожмите в zip-файл ваш каталог компонента или скачайте и установите его используя менеджер расширений. Протестируйте установленный компонент вставив index.php?option=com_helloworld и administrator/index.php?option=com_helloworld в адресную строку браузера, также вы сможете заметить что компонент виден в панели администратора сайта в меню Components.

Листинг Helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.7.0" method="upgrade">
 
    <name>Hello World!</name>
    <!-- The following elements are optional and free of formatting constraints -->
    <creationDate>November 2009</creationDate>
    <author>John Doe</author>
    <authorEmail>Этот адрес электронной почты защищен от спам-ботов. У вас должен быть включен JavaScript для просмотра.</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.7 -->
        <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>


site/helloworld.php

Hello World


admin/helloworld.php

Hello World administration


index.html для всех каталогов:

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

 

Интересная статья? Поделись ей с другими: