Difference between revisions of "Using Joomla Ajax Interface/ru"
From Joomla! Documentation
(Created page with "Поддержка модулей реализована вызовом метода в файле <code>helper.php</code> модуля.") |
(Created page with "===Детали===") |
||
Line 37: | Line 37: | ||
Поддержка модулей реализована вызовом метода в файле <code>helper.php</code> модуля. | Поддержка модулей реализована вызовом метода в файле <code>helper.php</code> модуля. | ||
− | === | + | ===Детали=== |
Module requests must include the <code>module</code> variable in the URL, paired with the name of the module (i.e. <code>module=session</code> for <code>mod_session</code>). | Module requests must include the <code>module</code> variable in the URL, paired with the name of the module (i.e. <code>module=session</code> for <code>mod_session</code>). |
Revision as of 21:40, 28 May 2015
Что такое интерфейс Ajax Joomla! (com_ajax)
Компактный, расширяемый компонент, действующий в качестве точки входа для HTTP запросов для автономных модулей и плагинов, тем самым предоставляя им потенциал функциональности Ajax. Com_ajax в основном используют, в тех случаях, когда не являються разработчиками того компонента, с которым взаимодействует модуль или плагин.
ПРИМЕЧАНИЕ: Если Вы разработчик компонентов, Вам нет нужды применять com_ajax для имплементации функционала Ajax в неи. Вы можете это сделать напрямую в компоненте.
Примеры применения, включая но не ограничиваясь:
- Модуль, получающий данные средствами внешнего API.
- Модуль, взаимодействующий с компонентом, написаным не Вами.
- Плагин, реализующий схожую с API функциональность для организации потребления данных с Вашего сайта.
Анатомия запроса Ajax
Требуется
option=com_ajax
[module|plugin]=name
format=[json|debug|raw]
Опционально
method=[custom fragment]
по умолчанию становитсяget
, если опущено.
Обзор
Все запросы начинаются с ?option=com_ajax
, который вызывает это расширение, и должны содержать в себе, тип расширения для вызова , и должны возвращать формат данных.
Дополнительные переменные и значния, используемые Вашим расширением также могут быть включены в URL
Например запрос к ?option=com_ajax&module=session
может вызывать mod_session
с результатами возвращенными в формате по умолчанию, и напротив ?option=com_ajax&plugin=session&format=json
запустит onAjaxSession
группу плагинов с выводом результата в JSON.
Поддержка модулей
Обобщение
Поддержка модулей реализована вызовом метода в файле helper.php
модуля.
Детали
Module requests must include the module
variable in the URL, paired with the name of the module (i.e. module=session
for mod_session
).
This value is also used for:
- The name of the directory to check for the helper file, e.g.
/modules/mod_session/helper.php
- The class name to call, e.g.
modSessionHelper
Optionally, the method
variable may be included to override the default method prefix of get
.
- NOTE: All methods must end in
Ajax
. For example: method=mySuperAwesomeMethodToTrigger
will callmySuperAwesomeMethodToTriggerAjax
The Ajax Session Module is an example module that demonstrates this functionality.
Plugin Response
Summary
Plugin support is accomplished by triggering the onAjax[Name]
plugin event.
Details
Plugin requests must include the plugin
variable in the URL, paired with the name of the plugin event, e.g. plugin=session
for onAjaxSession
.
This value is also used for:
- The plugin class name following the
plgAjax[Name]
convention. - The plugin function name following the
onAjax[Name]
convention. - The default plugin group is
ajax
. You can change it specifying thegroup
request parameter. (From Joomla! 3.4)
The Ajax Latest Articles plugin is an example plugin that demonstrates this functionality.
Response Format
format=[json|debug]
is an optional argument for the results format:
json
for JSON formatdebug
for human-readable output of the results.