When a field selector is used to load values or a web interface wants to interact with a back end process, a useful design pattern to use is Ajax MVC.
This works very well with jQuery, PHP and a database.
MVC
Model
The model is a map of how data is stored. The model may also provide object structures that inform the view how to use data.
View
The view is a form with active fields that talk to the controller. The fastest way to make an interactive view is using a smart template system such as TAL or Smarty.
Controller
The controller mediates messages from the view, and formats data according to the Model which gets delivered to the view.
Intelligent View
Ajax requires that the View contains scripting that allows page elements to POST and GET data. HTTP has several methods of packaging data to be sent to the server.
RESTful Web services
RESTful webservices conceptually implement PUT and POST. GET is simply used to sent record filters (i.e. selection criteria) and is considered "Safe" - that means that it must never be possible to change data in the Model using a GET. This prevents user database poisoning by URL.
HTML 5 allows PUT - which simply means record establishment. If you PUT a record that already exists - it will create another record, or better, results in an error condition. XHTML does not incorporate PUT, so it is common practise to overload POST.
POST is common to all versions of HTTP and is implemented in HTML 4.x and XHTML. POST packages and sends data via a mechanism (called Standard Input) that is not available for hacking except by modifying the form sending the data. Of course it is possible to do that, so some serialisation or encoding is important, minimally a timestamp and a hash that ensures that the data is recognised as valid.
No comments:
Post a Comment