-
Notifications
You must be signed in to change notification settings - Fork 36
Description
The documentation for Phery::set() reads:
set( array $functions )
Sets the functions to respond to the ajax call. For security reasons, these functions should not be reacheable through POST/GET requests. These will be set only for AJAX requests as it will only be set in case of an ajax request, to save resources.
You may set the config option "set_always_available" to true to always register the functions regardless of if it's an AJAX function or not going on.
The answer/process function, should have the following structure:
function func($ajax_data, $callback_data, $phery){ $r = new PheryResponse; // or PheryResponse::factory(); // Sometimes the $callback_data will have an item called 'submit_id', // is the ID of the calling DOM element. // if (isset($callback_data['submit_id'])) { } // $phery will be the current phery instance that called this callback $r->jquery('#id')->animate(...); return $r; //Should always return the PheryResponse unless you are dealing with plain text }Parameters
$functions
array
$functions An array of functions to register to the instance.array( 'function1' => 'function', 'function2' => array($this, 'method'), 'function3' => 'StaticClass::name', 'function4' => array(new ClassName, 'method'), 'function5' => function($data){} );Returns
Phery
Which ajax call this refers to is unclear. The description of $functions suggests the elements should be functions, but that is not always the case, as seen in the first 3 elements. This also fails to specify that the array must be string-indexed. This is mentioned in the README's take on that function, which uses the synopsis "Phery::instance()->set(array $functions)":
Register the functions that will be triggered by AJAX calls. The key is the function alias, the value is the function itself.
<?php function outside($ajax_data, $callback_data){ return PheryResponse::factory(); } class classy { function inside($ajax_data, $callback_data){ return PheryResponse::factory(); } static function inside_static($ajax_data, $callback_data){ return PheryResponse::factory(); } } $class = new classy(); Phery::instance()->set(array( 'alias' => function(){ return PheryResponse::factory(); }, 'outside' => 'outside', 'class' => array($class, 'inside'), 'class' => 'classy::inside_static', 'namespaced' => 'namespaced\function' )); ?>Callback/response function comprises of:
<?php function func($ajax_data, $callback_data, $phery_instance){ // $ajax_data = data coming from browser, via AJAX // // $callback_data = can have anything you specify, plus additional information, like **submit_id** that // comes automatically from the AJAX request, containing the ID of the calling DOM element, if has an id="" set // // $phery_instance = the current instance of Phery // return PheryResponse::factory(); // In most cases, you'll want to return a PheryResponse object } ?>
I do not know what the last sentence was meant to read, but it is invalid as it stands. Either a whole comprises parts, or a whole is comprised of parts. x cannot "comprise of" y. French has 2 distinct verbs for that ("est constitué de" vs "comprend").