AJAX
[ class tree: AJAX ] [ index: AJAX ] [ all elements ]

Source for file auto_server.php

Documentation is available at auto_server.php

  1. <?php
  2. /**
  3.  * Advanced usage of HTML_AJAX_Server
  4.  * Allows for a single server to manage exporting a large number of classes without high overhead per call
  5.  * Also gives a single place to handle setup tasks especially useful if session setup is required
  6.  *
  7.  * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir
  8.  * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead
  9.  *
  10.  * @category   HTML
  11.  * @package    AJAX
  12.  * @author     Joshua Eichorn <josh@bluga.net>
  13.  * @copyright  2005 Joshua Eichorn
  14.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  15.  * @version    Release: @package_version@
  16.  * @link       http://pear.php.net/package/HTML_AJAX
  17.  */
  18.  
  19.  // include the server class
  20. include 'HTML/AJAX/Server.php';
  21.  
  22.  
  23. // extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on
  24. class TestServer extends HTML_AJAX_Server {
  25.     // this flag must be set to on init methods
  26.     
  27.     var $initMethods = true;
  28.  
  29.     // init method for the test class, includes needed files an registers it for ajax
  30.     
  31.     function initTest({
  32.         include 'support/test.class.php';
  33.         $this->registerClass(new test());
  34.     }
  35.  
  36.     // init method for the livesearch class, includes needed files an registers it for ajax
  37.     
  38.     function initLivesearch({
  39.         include 'support/livesearch.class.php';
  40.         $this->registerClass(new livesearch());
  41.     }
  42.  
  43.     // init method for the testHaa class, includes needed files an registers it for ajax, directly passes in methods to register to specify case in php4
  44.     
  45.     function initTestHaa({
  46.         include 'support/testHaa.class.php';
  47.         $this->registerClass(new testHaa(),'testHaa',array('updateClassName','greenText','highlight','duplicate'));
  48.     }
  49.     
  50.     
  51. }
  52.  
  53. // create an instance of our test server
  54. $server = new TestServer();
  55.  
  56. // init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods
  57. class initObject {
  58.     // init method for the test class, includes needed files an registers it for ajax
  59.     
  60.     function initTest2({
  61.         include 'support/test2.class.php';
  62.         $this->server->registerClass(new test2());
  63.     }
  64. }
  65. $init = new initObject();
  66. $server->registerInitObject($init);
  67.  
  68. // you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can
  69. // use just one javascript include for all your library files 
  70. // example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib
  71.  
  72. $server->registerJSLibrary('customLib','customLib.js','./support/');
  73.  
  74. // handle requests as needed
  75. $server->handleRequest();
  76. ?>

Documentation generated on Sat, 05 May 2007 18:00:10 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.