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: 0.5.4
  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.     var $initMethods = true;
  27.  
  28.     // init method for the test class, includes needed files an registers it for ajax
  29.     function initTest({
  30.         include 'support/test.class.php';
  31.         $this->registerClass(new test());
  32.     }
  33.  
  34.     // init method for the livesearch class, includes needed files an registers it for ajax
  35.     function initLivesearch({
  36.         include 'support/livesearch.class.php';
  37.         $this->registerClass(new livesearch());
  38.     }
  39.  
  40.     // 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
  41.     function initTestHaa({
  42.         include 'support/testHaa.class.php';
  43.         $this->registerClass(new testHaa(),'testHaa',array('updateClassName','greenText','highlight','duplicate'));
  44.     }
  45.     
  46.     
  47. }
  48.  
  49. // create an instance of our test server
  50. $server = new TestServer();
  51.  
  52. // 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
  53. class initObject {
  54.     // init method for the test class, includes needed files an registers it for ajax
  55.     function initTest2({
  56.         include 'support/test2.class.php';
  57.         $this->server->registerClass(new test2());
  58.     }
  59. }
  60. $init = new initObject();
  61. $server->registerInitObject($init);
  62.  
  63. // you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can
  64. // use just one javascript include for all your library files 
  65. // example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib
  66. $server->registerJSLibrary('customLib','customLib.js','./support/');
  67.  
  68. // handle requests as needed
  69. $server->handleRequest();
  70. ?>

Documentation generated on Fri, 04 Apr 2008 18:30:12 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.