DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:components

components Plugin

Compatible with DokuWiki

2015-08-10a

plugin Defines some easy interfaces for AJAX function handlers and action handlers/renderers

Last updated on
2015-12-21
Provides
Action
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with action, ajax

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Examples/Usage

New action handlers/renderers

All new action handlers should be put under your plugin's commands folder, with a php script name identical to your command name. For example, if you want to implement an example_action action for your plugin named example, you need to put commands/example.php under your plugin folder. This defines an action example.example_action. Your script should as lead extend the Doku_Action class, which defines a handler, and its handle class can return an action name to change the processing to the action that you returned. If you do not change to another action, you must define a renderer for this action by extending the Doku_Action_Renderer class. Its xhtml() function's standard output is the action rendering output.

See the commands/example.php in this source repo. To see this in action, add a link to ?do=components.example&tag=pre to your page.

AJAX function call handler

All new AJAX function call should extend the Doku_AJAX class, and be put in your plugin's ajax folder, with a name identical to your AJAX function. For example, if you want to implement a function example_call in your plugin named example, you should name the script ajax/example.php. This defines an AJAX function call named example.example_call. The caller should pass in a data object that contains

{
   call: example.example_call,
   sectok: your_sectok,
   param1: some_value1,
   param2: some_value2 //etc, you can put as many parameters as you need to
}

Your ajax handler class should implement the call($parmas) function, which returns a PHP array/string/number/bool, this return value is automatically encoded as JSON and sent to the client. The $params argument is an array holding the passed in parameters. To specify the parameters, the constructor should call the parent's constructor with two parameters, the first is an array of required parameters, keys are the parameter names, and values are the parameter types. The second is an optional parameter array in the same format. For example,

public function __construct() {
    parent::__construct(
        array('param1' => 'array', 'param2' => 'string')
    );
}

See the ajax/example.php and script.js for an example. To see the example in action, put <slice from="1" to="5"/> in your wiki to see aslice of the first 5 characters in your raw wiki text.

Development

Change Log

  • 2015-12-21d
    • A working initial release.

Known Bugs and Issues

ToDo/Wish List

FAQ

Discussion

plugin/components.txt · Last modified: 2018-10-13 18:56 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki