\Dewdrop\FieldsEdit

Use the \Dewdrop\Db\Field API to manage the editing of values.

Adding fields to this object simplifies a couple aspects of the common add/edit workflow in a web application:

  1. It automatically attaches the added fields to the input filter for filtering and validation. The InputFilter will be injected into the constructor so that it can be integrated into some other context like an EditAbstract sub-class.
  2. When calling setValues(), this fields collection will automatically only set values on fields that you've explicitly added to the collection. For example, a malicious user adding a field you did not intend to allow them to edit to their POST data would be thwarted by this API. In other words, this API is intended as a way to prevent mass assignment (http://en.wikipedia.org/wiki/Mass_assignment_vulnerability). Think of adding a field to this object as passing a signed permission slip to the user saying they are allowed to edit that field on that particular row.
  3. When calling setValues(), this object will take care of odd quirks in input processing. For example, when a checkbox is unchecked, it is excluded completely from the POST data. This object will find boolean fields and if they are not in POST at all, set their values to false instead of just skipping over them while setting values for other fields whose control names _do_ appear in the supplied values hash.

Summary

Methods
Properties
Constants
__construct()
add()
get()
has()
setValues()
count()
current()
key()
next()
prev()
rewind()
valid()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$fields
$inputFilter
$currentIndex
N/A

Properties

$fields

$fields : array

The collection of fields added to this object

Type

array

$inputFilter

$inputFilter : \Zend\InputFilter\InputFilter

Object used to filter and validate user input

Type

\Zend\InputFilter\InputFilter

$currentIndex

$currentIndex : integer

Index used for iterator interface.

Type

integer

Methods

__construct()

__construct(\Zend\InputFilter\InputFilter  $inputFilter) 

Store reference to supplied InputFilter so that fields can be added to it at the same time they're added to this object.

Parameters

\Zend\InputFilter\InputFilter $inputFilter

add()

add(\Dewdrop\Db\Field  $field, string  $groupName = null) : \Dewdrop\Fields\Edit

Add a field, optionally changing its control name to disambiguate it from other fields with the same control name on this page.

Parameters

\Dewdrop\Db\Field $field
string $groupName

Returns

\Dewdrop\Fields\Edit

get()

get(string  $controlName) : \Dewdrop\Db\Field

Get the field matching the supplied control name.

Parameters

string $controlName

Throws

\Dewdrop\Exception

Returns

\Dewdrop\Db\Field

has()

has(string  $controlName) : boolean

Check to see if this object has a reference to the field with the provided control name.

Parameters

string $controlName

Returns

boolean

setValues()

setValues(array  $values) : \Dewdrop\Fields\Edit

Set values for any fields managed by this object with a control name matching a key of the supplied $values array.

This method is also responsible for transforming the input when necessary for it to be useful for the database. For example, when unchecked, HTML inputs of type "checkbox" will not be present in POST at all. In that case, this method will detect that the POST key is absent and set the assocaited field's value to zero.

Parameters

array $values

Returns

\Dewdrop\Fields\Edit

count()

count() : integer

Get a count of the fields added to this collection.

Returns

integer

current()

current() : \Dewdrop\Db\Field

Retrieve the current field during iteration.

Returns

\Dewdrop\Db\Field

key()

key() : integer

Return the current index during iteration.

Returns

integer

next()

next() : void

Advance to the next index during iteration.

prev()

prev() : void

Seek to the previous index.

rewind()

rewind() : void

Return the iteration index to the initial position.

valid()

valid() : boolean

Test to see if an item is present at the current index during iteration.

Returns

boolean