- <?php
- // include the server class
- include 'HTML/AJAX/Server.php';
-
- // extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on
- class LiveText extends HTML_AJAX_Server {
- // this flag must be set to on init methods
-
- var $initMethods = true;
-
- // simple search
-
- var $LiveText = array(
- 1 => 'Orange',
- 2 => 'Apple',
- 3 => 'Pear',
- 4 => 'Banana',
- 5 => 'Blueberry',
- );
-
- // search with complex result
-
- var $LiveText2 = array(
- 'Alice' => array('id' => 0, 'name' => 'Alice', 'department' => 'Managment'),
- 'Fabio' => array('id' => 1, 'name' => 'Fabio', 'department' => 'Development'),
- 'John' => array('id' => 2, 'name' => 'John', 'department' => 'Systems'),
- 'Joe' => array('id' => 31, 'name' => 'Joe', 'department' => 'Development'),
- 'Bob' => array('id' => 4, 'name' => 'Bob', 'department' => 'Systems'),
- 'Jonathan' => array('id' => 20, 'name' => 'Jonathan', 'department' => 'Systems'),
- 'Joaquin' => array('id' => 21, 'name' => 'Joaquin', 'department' => 'Development'),
- 'Jody' => array('id' => 10, 'name' => 'Jody', 'department' => 'Managment'),
- );
-
- /**
- * Perform a search
- *
- * @return array
- */
- function search($input) {
- $ret = array();
- foreach($this->LiveText as $key => $value) {
- if (stristr($value,$input)) {
- $ret[$key] = $value;
- }
- }
- return $ret;
- }
-
- function search2($input) {
- $ret = array();
- foreach($this->LiveText2 as $key => $value) {
- if (stristr($key,$input)) {
- $ret[$key] = $value;
- }
- }
- return $ret;
- }
-
- // init method for the LiveText class, includes needed files an registers it for ajax
-
- function initLiveText() {
- $this->registerClass(new LiveText());
- }
- }
-
- // create an instance of our test server
- $server = new LiveText();
- $server->handleRequest();
- ?>