Class phery

Description

Main class

Located in /phery.php (line 30)


	
			
Variable Summary
Method Summary
static phery factory ([ $config = null])
static void form_for (string $action, string $function, [ $attributes = array()], [phery $phery = null])
static phery instance ([ $config = null])
static bool is_ajax ()
static string link_to (string $title, string $function, [ $attributes = array()], [phery $phery = null])
phery __construct ([ $config = null])
mixed answer_for (string $alias, [ $default = NULL])
phery callback ( $callbacks)
phery config ( $config)
phery data ( $args, mixed $args,...)
void process ([bool $last_call = true])
phery set ( $functions)
void __get ( $name)
void __set ( $name,  $value)
Variables
array $config = null (line 73)

Config

  1.  'exit_allowed',
  2.  'no_stripslashes',
  3.  'exceptions',
  4.  'unobstructive'

mixed $last_response = null (line 78)

Last response

  • access: public
array $unobstructive = array() (line 57)

Will call the functions defined in this variable even

if it wasn't sent by AJAX, use it wisely. (good for SEO though)

  • access: public
Methods
static method factory (line 486)

Create a new instance of phery

static phery factory ([ $config = null])
  • array $config: Associative config array
static method form_for (line 578)

Create a <form> tag with ajax enabled. Must be closed manually with </form>

  • return: Echoes automatically
static void form_for (string $action, string $function, [ $attributes = array()], [phery $phery = null])
  • string $action: where to go, can be empty
  • string $function: Registered function name
  • array $attributes:
    1.  'confirm' => 'Are you sure?',
    2.  'data-type' => 'json',
    3.  'submit' => array('all' => true'disabled' => true// 'all' submits all elements on the form, even if empty or not checked, disabled also submit disabled elements
  • phery $phery: Pass the current instance of phery, so it can check if the functions are defined, and throw exceptions
static method instance (line 421)

Generates just one instance. Useful to use in many included files. Chainable

static phery instance ([ $config = null])
  • array $config: Associative config array
static method is_ajax (line 212)

Check if the current call is an ajax call

static bool is_ajax ()
static method link_to (line 508)

Helper function that generates an ajax link, defaults to "A" tag

static string link_to (string $title, string $function, [ $attributes = array()], [phery $phery = null])
  • string $title: The content of the link
  • string $function: The PHP function assigned name on phery::set()
  • array $attributes: Extra attributes that can be passed to the link, like class, style, etc
    1.  'confirm' => 'Are you sure?' // Display confirmation on click
    2.  'tag' => 'a' // The tag for the item, defaults to a
    3.  'href' => '/path/to/url' // Define another URI for the AJAX call, this defines the HREF of A
    4.  'args' => array(1"a"// Extra arguments to pass to the AJAX function, will be stored in the args attribute as a JSON notation
    5.  'target' => '/default/ajax/controller' // Set the "href" attriute for non-anchor (a) AJAX tags (like buttons or spans). Works for A links too, it won't function without javascript
    6.  'data-type' => 'json' // Define the data-type for the communication
  • phery $phery: Pass the current instance of phery, so it can check if the functions are defined, and throw exceptions
Constructor __construct (line 83)

Construct the new phery instance

phery __construct ([ $config = null])
  • $config
answer_for (line 242)

Return the data associatated with a processed unobstructive POST call

  • return: Return $default if no data available, defaults to NULL
mixed answer_for (string $alias, [ $default = NULL])
  • string $alias: The name of the alias for the process function
  • $default
callback (line 133)

Set callbacks for pre and post filters. Callbacks are useful for example, if you have 2

or more AJAX functions, and you need to perform the same data manipulation, like removing an 'id' from the $_POST['args'], or to check for potential CSRF or SQL injection attempts on all the functions, clean data or perform START TRANSACTION for database, etc

phery callback ( $callbacks)
  • array $callbacks:
    1.  'pre' => array|function // Set a function to be called BEFORE processing the request, if it's an AJAX to be processed request, can be an array of callbacks
    2.  'post' => array|function // Set a function to be called AFTER processing the request, if it's an AJAX processed request, can be an array of callbacks
    The callback function should be
    1.  // $additional_args is passed using the callback_data() function, in this case, a pre callback
    2.  function pre_callback($ajax_data$internal_data){
    3.    // Do stuff
    4.    $_POST['args']['id'$additional_args['id'];
    5.    return true;
    6.  }
    7.  // post callback would be to save the data perhaps? Just to keep the code D.R.Y.
    8.  function post_callback($ajax_data$internal_data){
    9.    $this->database->save();
    10.    return true;
    11.  }
    Returning false on the callback will make the process() phase to RETURN, but won't exit. You may manually exit on the post callback if desired Any data that should be modified will be inside $_POST['args'] (can be accessed freely on 'pre', will be passed to the AJAX function)
config (line 386)

Config the current instance of phery

phery config ( $config)
  • array $config: Associative array containing the following options
    1.  'exit_allowed' => true/false // Defaults to true, stop further script execution
    2.  'no_stripslashes' => true/false // Don't apply stripslashes on the args
    3.  'exceptions' => true/false // Throw exceptions on errors
    4.  'unobstructive' => array('function-alias-1','function-alias-2'// Set the functions that will be called even if is a POST but not an AJAX call
data (line 201)

Set any data to pass to the callbacks

phery data ( $args, mixed $args,...)
  • mixed $args,...: Parameters, can be anything
  • $args
process (line 359)

Process the AJAX requests if any

void process ([bool $last_call = true])
  • bool $last_call: Set this to false if any other further calls to process() will happen, otherwise it will exit
set (line 449)

Sets the functions to respond to the ajax call.

For security reasons, these functions should not be available for direct POST/GET requests. These will be set only for AJAX requests as it will only be called in case of an ajax request, to save resources. The answer/process function, must necessarily have the following structure:

  1.  function func($ajax_data$callback_data){
  2.    $r new phery_response// or phery_response::factory();
  3.    // Sometimes the $callback_data will have an item called 'submit_id',
  4.    // is the ID of the calling DOM element.
  5.    // if (isset($callback_data['submit_id'])) {  }
  6.    $r->jquery('#id')->animate(...);
  7.       return $r;
  8.  }

phery set ( $functions)
  • array $functions: An array of functions to register to the instance.
__get (line 630)
  • access: public
void __get ( $name)
  • $name
__set (line 625)
  • access: public
void __set ( $name,  $value)
  • $name
  • $value

Documentation generated on Sun, 01 May 2011 12:28:29 -0300 by phpDocumentor 1.4.3