File: examples/ajax/fromwact.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil  >  PHP Skeleton Framework  >  examples/ajax/fromwact.php  >  Download  
File: examples/ajax/fromwact.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Skeleton Framework
Extensive Web application development framework
Author: By
Last change:
Date: 5 years ago
Size: 3,063 bytes


Class file image Download
require_once '../'; //loads
require_once WACT_ROOT . 'controller/';
WACT_ROOT . 'view/';
Application extends DecoratingController{
$responder = new PathInfoDispatchController();
//the search command will handle the search logic
$searchCommand = new CommandController(new CallBack($this, 'search'));
$searchCommand->addParameter(new PostParameter('name'));
$responder->addPublicChild('search', $searchCommand);
$this->addPublicChild('responder', $responder);
$responder->addChild('searchResponse', new ViewController(new View('/results.html')));
$this->setView(new AppView('/application.html'));
search(& $sender, & $request, & $responseModel){
$results = array(array('name' => 'Winnipeg'),
'name' => 'Toronto'),
'name' => 'Auckland'),
'name' => 'Singapore'),
'name' => 'Penang'));
$results[] = array('name' => $request->getParameterValue('name'));
//we're not doing any real filtering here, just sending content back to the client browser
$responseModel->set('results', $results);
//returning searchResponse will redirect control to the ViewController in the new controller
return 'searchResponse';
AppView extends View{
prepareModel(& $source, & $request, & $responseModel){
$responseModel->set('title', 'Application Controller');
$responseModel->set('page_header', 'Demonstration of new WACT Controller Architecture');
$app = new Application;
The script block below automagically performs the linking of the textbox(ac1), the Ajax request and the response container(ac1update). When the value of the textbox changes, the onchange event will be triggered and the Prototype framework will compose a complete POST request to ‘/samples/controllers/application.php/search’. ‘application.php/search’ will direct the request to the CommandController named ‘search’ that’s been registered as the child of the root PathInfoDispatchController.

<script type="text/javascript" language="javascript">
// <![CDATA[
    new Ajax.Autocompleter('ac1','ac1update','/samples/controllers/application.php/search');
// ]]>

The results array will be populated in results.html

<list:list from="results">

The populated template will be sent back as the response to the POST request made by the autocompleter. Once the autocompleter receives the response from the server, it will insert the unordered list into the container specified (ac1update) as innerHTML.

And there you have it, Ajax goodness with WACT!

For more information send a message to info at phpclasses dot org.