PHruts

3. Building View Components

3.1 Overview

This chapter focuses on the task of building the View components for use with the PHruts framework. The PHruts distribution includes an API library that provides support for building internationalized applications, as well as for interacting with input forms. Several other topics related to the View components are briefly discussed.

3.2 Internationalized Messages

PHruts includes classes to build internationalized and localized applications. The key concepts to become familiar with are:

Please note that the internationalization (often called "i18n" because 18 is the number of letters in between the "i" and the "n") support in a framework like PHruts is limited to the presentation of internationalized text and images to the user. Support for Locale specific input methods (used with languages such as Japanese, Chinese, and Korean) is left up to the client device, whichis usually a web browser.

Assume that your source code is created in package mycompany::mypackage, so it is stored in a directory (relative to your your application's classes folder) named mycompany/mypackage. To create a resource bundle called mycompany::mypackage::MyResources, you would create the following files in the mycompany/mypackage directory:

3.3 Automatic Form Validation

PHruts offers a facility to validate the input fields it has received. To utilize this feature, override the following method in your PHRUTS_ActionForm class:

validate(PHRUTS_ActionConfig $mapping, PHRUTS_HttpServiceRequest $request);

The validate method is called by the controller service after the bean properties have been populated, but before the corresponding action class's execute method is invoked. The validate method has the following options:

As mentioned earlier, this feature is entirely optional. The default implementation of the validate method returns null, and the controller service will assume that any required validation is done by the action class.

One common approach is to perform simple, prima facia validations using the ActionForm validate method, and then handle the "business logic" validation from the Action.

Previous: Building Model Components

Next: Building Controller Components

This documentation is a modified copy of the Apache Struts 1.1 framework user guide, and so is copyrighted under the ASF license.