setPluginLoader($loader, $type):
$loader is the plugin loader object itself, while
$type is one of the types specified above. This
sets the plugin loader for the given type to the newly
specified loader object.
getPluginLoader($type): retrieves the plugin
loader associated with $type.
addPrefixPath($prefix, $path, $type = null): adds
a prefix/path association to the loader specified by
$type. If $type is null, it will
attempt to add the path to all loaders, by appending the prefix
with each of "_Validate", "_Filter", and "_Decorator"; and
appending the path with "Validate/", "Filter/", and
"Decorator/". If you have all your extra form element classes
under a common hierarchy, this is a convenience method for
setting the base prefix for them.
addPrefixPaths(array $spec): allows you to add
many paths at once to one or more plugin loaders. It expects
each array item to be an array with the keys 'path', 'prefix',
and 'type'.
getValue():
addPrefixPath(). For instance, if you have
filters under the 'My_Filter' prefix, you can tell
getUnfilteredValue() method:
addFilter($nameOfFilter, array $options = null)
addFilters(array $filters)
setFilters(array $filters) (overwrites all filters)
getFilter($name) (retrieve a filter object by name)
getFilters() (retrieve all filters)
removeFilter($name) (remove filter by name)
clearFilters() (remove all filters)
addPrefixPath(). For instance, if you have
validators under the 'My_Validator' prefix, you can tell
addValidator() as an
array:
$min and $max parameters:
$options argument of the
addValidators(). The basic usage is to pass an array
of arrays, with each array containing 1 to 3 values, matching the
constructor of addValidator():
isValid():
$context.
$context when validating a
form, and breakChainOnFailure value fails its validation. Be
sure to specify your validators in a reasonable order.
setRequired(true). By default, this
flag is false, meaning that your validator chain will be skipped if
no value is passed to isValid(). You can modify this
behavior in a number of ways:
isValid(), the
validators will be skipped. You can toggle this flag using
the accessor setAllowEmpty($flag); when the
flag is false and a value is passed, the validators
will still run.
isValid() will add one
to the top of the stack, with the
breakChainOnFailure flag set. This behavior lends
required flag semantic meaning: if no value is passed,
we immediately invalidate the submission and notify the
user, and prevent other validators from running on what we
already know is invalid data.
setAutoInsertNotEmptyValidator($flag); this
will prevent isValid() from placing the
'NotEmpty' validator in the validator chain.
setRequired($flag) and
isRequired() allow you to set and retrieve the
status of the 'required' flag. When set to boolean setAllowEmpty($flag) and
getAllowEmpty() allow you to modify the
behaviour of optional elements (i.e., elements where the
required flag is false). When the 'allow empty' flag is
true, empty values will not be passed to the validator
chain.
setAutoInsertNotEmptyValidator($flag) allows
you to specify whether or not a 'NotEmpty' validator will be
prepended to the validator chain when the element is
required. By default, this flag is true.
addValidator($nameOrValidator, $breakChainOnFailure = false, array $options =
null)
addValidators(array $validators)
setValidators(array $validators) (overwrites all validators)
getValidator($name) (retrieve a validator object by name)
getValidators() (retrieve all validators)
removeValidator($name) (remove validator by name)
clearValidators() (remove all validators)
addErrorMessage($message): add an error message
to display on form validation errors. You may call this more
than once, and new messages are appended to the stack.
addErrorMessages(array $messages): add multiple
error messages to display on form validation errors.
setErrorMessages(array $messages): add multiple
error messages to display on form validation errors,
overwriting all previously set error messages.
getErrorMessages(): retrieve the list of
custom error messages that have been defined.
clearErrorMessages(): remove all custom error
messages that have been defined.
markAsError(): mark the element as having
failed validation.
hasErrors(): determine whether the element has
either failed validation or been marked as invalid.
addError($message): add a message to the custom
error messages stack and flag the element as invalid.
addErrors(array $messages): add several
messages to the custom error messages stack and flag the
element as invalid.
setErrors(array $messages): overwrite the
custom error messages stack with the provided messages and
flag the element as invalid.
This is some descriptive text regarding the element.
addDecorator(), pass an array with a
single element, with the alias pointing to the decorator object
or name:
addDecorators() and
setDecorators() methods, you will need to pass
the 'decorator' option in the array representing the decorator:
addDecorator($nameOrDecorator, array $options = null)
addDecorators(array $decorators)
setDecorators(array $decorators) (overwrites all decorators)
getDecorator($name) (retrieve a decorator object by name)
getDecorators() (retrieve all decorators)
removeDecorator($name) (remove decorator by name)
clearDecorators() (remove all decorators)
__call() will intercept methods
that lead with the text 'render' and use the remainder of the method
name to lookup a decorator; if found, it will then render that
render() method. As an example:
setName() and getName() accessors.
setLabel() and getLabel() accessors.
setOrder() and
getOrder() accessors.
setValue() and getValue() accessors.
setDescription() and getDescription()
accessors.
setRequired() and getRequired()
accessors. This flag is false by default.
setAllowEmpty() and getAllowEmpty()
accessors. This flag is true by default.
setAutoInsertNotEmptyValidator($flag) and
determine the value with
autoInsertNotEmptyValidator().
setOptions(array $options)setConfig(Zend_Config $config)setTranslator(Zend_Translate_Adapter $translator = null)
getTranslator()setDisableTranslator($flag)translatorIsDisabled()setName($name)getName()setValue($value)getValue()getUnfilteredValue()setLabel($label)getLabel()setDescription($description)getDescription()setOrder($order)getOrder()setRequired($flag)getRequired()setAllowEmpty($flag)getAllowEmpty()setAutoInsertNotEmptyValidator($flag)autoInsertNotEmptyValidator()setIgnore($flag)getIgnore()getType()setAttrib($name, $value)setAttribs(array $attribs)getAttrib($name)getAttribs()setPluginLoader(Zend_Loader_PluginLoader_Interface $loader,
$type)
getPluginLoader($type)addPrefixPath($prefix, $path, $type = null)addPrefixPaths(array $spec)addValidator($validator, $breakChainOnFailure = false, $options =
array())
addValidators(array $validators)setValidators(array $validators)getValidator($name)getValidators()removeValidator($name)clearValidators()isValid($value, $context = null)getErrors()getMessages()addFilter($filter, $options = array())addFilters(array $filters)setFilters(array $filters)getFilter($name)getFilters()removeFilter($name)clearFilters()setView(Zend_View_Interface $view = null)getView()addDecorator($decorator, $options = null)addDecorators(array $decorators)setDecorators(array $decorators)getDecorator($name)getDecorators()removeDecorator($name)clearDecorators()render(Zend_View_Interface $view = null)setOptions() or setConfig(). Generally
speaking, keys are named as follows:
prefixPath will be passed to
addPrefixPaths()
setAttrib (though
setAttribs setConfigsetOptionssetPluginLoadersetTranslatorsetViewinit(), which can be used to add custom initialization
logic to your element, and loadDefaultDecorators(),
which can be used to set a list of default decorators used by your
element.
StringTrim,
validated with a common regular expression, and that you want to
use a custom decorator you've created for displaying them,
'My_Decorator_TextItem'. In addition, you have a number of standard
attributes, including 'size', 'maxLength', and 'class' you wish to
specify. You could define an element to accomplish this as follows:
My_Element_Text,
and exhibit the behaviour you've outlined.
loadDefaultDecorators() method. This method
conditionally loads a set of default decorators for your element;
you may wish to substitute your own decorators in your extending
class: