Php Object Generator Tutorials
  1. Introduction to POG
  2. Setting up PHP, MySQL etc.
  3. Designing your objects
  4. Generating your code
  5. Description of the generated code
  6. Edit configuration file
  7. The Setup Process
  8. Using the code: Save()
  9. Using the code: Get()
  10. Using the code: SaveNew()
  11. Using the code: GetList()
  12. Using the code: Delete()
  13. Using the code: DeleteList()
  14. Advanced: object relations
  15. Advanced: Set{Parent}()
  16. Advanced: Get{Parent}()
  17. Advanced: Add{Child}()
  18. Advanced: Get{Child}List()
  19. Advanced: Save(deep)
  20. Advanced: Delete(deep)
  21. Advanced: Add{Sibling}()
  22. Advanced: Set{Child}List()
  23. Advanced: Set{Sibling}List()
  24. Advanced: Get{Sibling}List()
  25. Advanced: DeleteList(deep)
  26. Customizing POG-generated code
  27. Customizing: Extending POG Objects
  28. Customizing: Plugins
  29. Examples
  30. Examples: User registration system
  31. Examples: User authentication
  32. Examples: Survey form
  33. Examples: Using POG with AJAX
  34. PDO: Introduction
  35. PDO: SQLite example
  36. PDO: Firebird example
  37. PDO: PostgreSQL example
  38. PDO: MySQL example
  39. PDO: ODBC example
  40. Troubleshooting
  41. Troubleshooting: Data appears encoded
  42. Troubleshooting: Can't regenerate object
  43. Troubleshooting: Can't seem to Save()
  44. Troubleshooting: Can't get object / object attributes from database
  45. Troubleshooting: Can't open zip file on Mac
  46. Troubleshooting: Setup screen is blank
  47. Videos
  48. Appendix: Creating table(s) manually
  49. Appendix: Regenerating objects
  50. Appendix: Generating objects using SOAP
  51. Case Study: Gravity GTD
  52. Case Study: Web Form Factory

Want more Php Object Generator?
Back to the Code Generator
The POG Weblog and RSS feed.
The POG Google group

Examples: Using POG with AJAX

AJAX, as you must have heard already, is a set of not-so-new technologies (Javascript, XML, CSS) which allows developers to design web applications with minimal server post-backs. The main difference this technique offers over “traditional” or “Web 1.0” applications is a more responsive and interactive graphical interface, since browser-server interactions occur behind the scenes without the need for a page refresh.

All the examples provided up to now in our tutorials have dealt with traditional scenarios: Usually a web form, PHP objects generated by POG and some plumbing code that joins them together. In this article, we’ll demonstrate how POG can also easily be used with an AJAX UI to create a simple to-do list. But first, if you’re not familiar with concepts related to AJAX, we recommend that you read this short article which gives a 30 second AJAX tutorial.

Using POG and AJAX is not much different than using POG and regular HTML or XHTML, because essentially, in both cases, you’re dealing with PHP objects in the back-end. Whatever happens in the front-end, whether there’s a server post-back or not, is quite irrelevant. For example, let’s say you’ve created a form that captures to-do items that are used to build a to-do list. The method used to post the input to the PHP objects doesn’t really matter, as long as they’re passed correctly. In the examples provided in our tutorials, we use plain html forms and server post-backs to pass the required information. In this current article, we’ll use AJAX.

Take a look at the live example below:

Note: The live example might not work if you are currently reading this article in your RSS feed reader.

Live Example:

New todo item:

In this example, whenever the “Add” button is clicked, the page makes a call to the javascript function sndReq with 2 parameters: action and todo. The sndReq function then asynchronously passes these 2 variables to rpc.php in the background. In rpc.php, we’ve added some code to handle 2 types of actions. If action is “Add”, then we create a Todo object, assign the value of todo to it, and save it. If action is “Get”, we simply get the last 5 to-do items and return them. If you followed the example on the 30-second tutorial site, you’ll notice that we essentially plugged in POG-related code in rpc.php to save and retrieve Todo objects. For aesthetic reasons, we also used a “Yellow Fade Technique” script to briefly highlight the most recently added to-do item.

Download the source code and take a look for yourself.

  1. Extract the zipped file into a folder on your server.
  2. Edit configuration.php with your database details.
  3. Run /setup/index.php and complete the 3 steps.
  4. Finally run /index.php and you should be able to add items to your to-do list.

We hope this provides somewhat of an overview of how POG can be used with AJAX web applications as well as traditional web applications. Whichever method you choose or prefer is your personal choice.

Additional Reading:
Here’s some additional links somewhat related to this post:
The Fade Anything Technique
The Yellow Fade Technique
moo.fx (super lightweight javascript effects library)
Prototype Javascript framework

POG documentation summary: