3.7. Handling Actions and Responding

Taking Action

Once PHOCOA determines that your form data is valid, it will call the action method corresponding to the button pressed by the user. If the validation fails at all, then the action method will not be called.

The action method is simply a method of the page delegate named "<action>Action". For instance, find the saveAction method in blog.php, which is called when the Save button is pressed.

Sometimes of course, there will be no errors during the bindings phase, but errors may still occur when processing the action. During the bindings phase, the validators are processed through simple Key-Value Validation. This by definition occurs one property at a time. However, some validation can't be done until all properties have been set. For instance, to validate a particular property, you may need to know the value of one or more other properties. Or, during the database update, the database might return an error. In this case, you can easily add additional errors using the addError function of WFPage. Now, of course you don't want your model classes to make WFPage method calls, so your model classes would simply throw an exception, and you would catch the exception from the action method and add the error to the page at that point. The saveAction implementation is an excellent example of this kind of handling.

Responding With a Different Page

Sometimes, to process your action, you just want to route the user to a different page. The deleteAction is an excellent example of this. Examine this method and notice the setupResponsePage call, which tells PHOCOA to render the response using a different page in the same module.

Alternatively, you can even redirect execution to a completely different module by throwing a WFRequestController_InternalRedirectException or WFRequestController_RedirectException, passing the desired URL as the first parameter.