What is ActionForm? (5)

XCube_ActionForm is a device at web’s requests for developer. But it doesn’t connect to database. XOOPS Cube recommends separating ActionForm from business logics and database.
To use values which ActionForm received, you can make XoopsSimpleObject relay. XCube_ActionForm has interfaces to do it.


You should implement the logic which copies values of $object to ActionForm in load(). XCube_ActionForm is difficult to have initial values. So you can use XoopsSimpleObject to set ActionForm. This method is important for edit function. If you send loaded object to ActionForm, it’s re-edit contents. If you send new object to ActionForm, it’s create contents. In other words, this is “Remove the difference of creating and editing”.
In addition, you can use this member function for special loading. For example, ActionForm can copy a value as string from $object’s integer value.


You should implement the logic which copies values of ActionForm to $object. This member function has to be called after validation successful. As well as load(), you can use this member function for special updating. For example, “modified date time” field should not be copied from user’s input values. In this case, you can always set time() to that field.
See example ActionForm in your myannounce module:

function update(&$obj)
$obj->set(‘update_unixtime’, time());
$obj->set(‘subject’, $form->get(‘subject’));
$obj->set(‘message’, $form->get(‘message’));

This upload() doesn’t overwrite ‘create_unixtime’. And, it use time() for ‘update_unixtime’. These techniques are used for protecting important field from users. For example, user’s ActionForm should not handle the field which only administrators can edit. If you understand this concept, you can switch ActionForm by user type:

$actionForm = $xoopsUser->isAdmin() ?
EditForm4Admin() : new EditForm4User();

This entry was posted in XOOPS Cube and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s