Ext AJAX Php Class
OO Update Class
This class is very simple, so the docs are quite succint :)
Basically we wrap a small subset of ExtJS inside a php class which allows you to update parts of your page in an AJAX fashion without needing to learn any javascript. Whilst this is useful on small scale applications - it is probably not up to scratch for enterprise useage.
Click here to download the zip file
Whats in the zip?
Included in the zip are the files required to make this work:
- index.php (this file)
- demo.php (a demo of whats on this page)
- class
- ooUpdateJS.php (the class file)
- js
- mini-ext.js (a standalone basic version of ExtJS)
- ooUpdateJS.js (the small js file used to do the AJAX)
- php
- updateJS.php (a demo php server side file)
How do you use it?
Invoke an instance of the class (require_once first) and use that across the page to access the class methods.
In the head area of your html page call the 2 javascript scripts
Almost done!
Now when you need to have a section of your page updated, call the link generation method with some parameters and the class will make the link correctly when you run the page.
Lets break that down a little:
- makeLinkDiv - this is the class method to make up the links to update a div (or similar area)
- makeLinkDiv('div','function',array(arguments))
- div = id of the div you need to update
- function = the 'method' in your php server side file
- arguments = any args you want to pass to the method (no limit) as an array
- makeLinkDiv('div','function',array(arguments))
Now create a server side php file
The server side file simply captures the request from javascript and processes it, it then returns JSON encoded text along with a status message (Success / Fail) which advises the javascript what to do.
You can do anything you like as long as you maintain a couple of things.
- You MUST:
- not rename the vars sent back to the javascript
- use html fragments - any other data is ignored
- use the status messages correctly - check the demo php file for the correct ones
An example of the above link would require code similar as follows:
Optional parameters which can be set:
There are a couple of optional parameters which can be used to tweak the way the class operates for your individual useage.
setPHPPath = this sets the path to your server side file from the web root
default: /classes/oo_update/php/updateJS.php
example: $update->setPHPPath('/your/path/here/myserverfile.php')
setJSPath = this sets the path to the javascript file from the web root
default: /classes/oo_update/js/ooUpdateJS.js
example: $update->setJSPath('/js/ooUpdateJS.js')
setEXTPath = this sets the path to the ExtJS file from the web root (you may already use one)
default: /classes/oo_update/js/mini-ext.js
example: $update->setEXTPath('/ext-2.0/ext-all.js')
ooUpdateJS is © Owen Lees 2008
(Apart from the Ext Library which most certaintly isnt!)
We used...
- Ext.Element : Provides methods/functions to retrive DOM/Page elements.
- get -> Pull an element from the DOM/page and work with it
- Ext.Data : Provides data services
- Ext.Ajax : Provides a simple way to make Ajax Requests
- request -> Pull data from server side
Try it out!
OO Update demo page.
This page demonstrates the AJAX update using the code samples above.
This is a link with the onClick part generated by the class....Click Me!
This is another link with the onClick part generated by the class, this time we insert some latinesque from the server side....Click me too!
We didnt use any arguments this time as the server script doesnt require any.
ooUpdateJS is © Owen Lees 2008
(Apart from the Ext Library which most certaintly isnt!)
