DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:components

components Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" unknown
  • 2016-06-26 "Elenor Of Tsort" unknown
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" unknown

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

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

Tagged with action, ajax

Installation

Install the plugin using the Plugin Manager and the download URL above, which points to latest version of the plugin. 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: 2016-01-22 22:34 by 142.104.7.212