Thursday, June 15, 2006

What is ActionForm? (3)

XCube_ActionFrom has the recommended procedure to get maximum impact. It's the following procedure:

  1. Construct
  2. Prepare
  3. (Load)
  4. Fetch
  5. Validate
  6. Error Check
  7. (Update)

XCube_ActionForm doesn't make frameworks about this procedure, but Legacy module uses it as ideal procedure. See typical code in the following:

$form =& new Myannounce_MessageEditForm();
$form->prepare();

$form->fetch();
$form->validate();

if (
$form->hasError()) {
// display error
}

In fact, developers don't need to type these codes because code generators generate various typical code. But, let's read these codes to understand the procedure.

Initialization

Call prepare() after new operator. Prepare() consists of generated code which is complex and long. So developers write their initialization code in constructor. In using, both of these functions has to be called.

Fetch

ActionForm gets input values from $_REQUEST and keeps into its properties. After fetching, these values can be accessed by get() member function.

ActionForm fetches specified values only, and does casting conversion with type setting. Therefore, developers don't need to think casting conversion as long as they use get(). If null byte or bad control code are sent to string property or text property, XCube_ActionFrom aborts the program.

If you are a video game programer, imagine getting values of a joypad. Perhaps, the special class for joypad might work in the special condition about joypad, then keeps values only. Most developers don't need to program to fight BIOS or device drivers. Also developers with ActionForm don't need to program for some special conditions of web.

Type settings of form property for casting conversion are BOOL, INT, FLOAT, STRING and TEXT. TEXT accepts CR and LF, but STRING doesn't accept them.

In addition, developers can override fetch() in each form properties. If you want to know this special usage, read the comment in source code or create a document from source code with document systems.

No comments: