Provides a form context around a single entity and its relations. It also can be used as context around an array or iterator of entities.
This class lets FormHelper interface with entities or collections of entities.
Important Keys:
entity The entity this context is operating on.table Either the ORM\Table instance to fetch schema/validators from, an array of table instances in the case of a form spanning multiple entities, or the name(s) of the table. If this is null the table name(s) will be determined using naming conventions.validator Either the Validation\Validator to use, or the name of the validation method to call on the table object. For example 'default'. Defaults to 'default'. Can be an array of table alias=>validators when dealing with associated forms.__construct( Cake\Network\Request $request , array $context )
Constructor.
Cake\Network\Request $request $context _extractMultiple( array|Traversable $values , array $path )
Helper method used to extract all the primary key values out of an array, The primary key column is guessed out of the provided $path array
$values $path array_getProp( mixed $target , string $field )
Read property values or traverse arrays/iterators.
$target $field mixed_getTable( array $parts , boolean $rootFallback true )
Get the table instance from a property path
$parts $rootFallback optional true Cake\ORM\Table|boolean_getValidator( array $parts )
Get the validator associated to an entity based on naming conventions.
$parts Cake\Validation\Validator_prepare( )
Prepare some additional data from the context.
If the table option was provided to the constructor and it was a string, ORM\TableRegistry will be used to get the correct table instance.
If an object is provided as the table option, it will be used as is.
If no table option is provided, the table name will be derived based on naming conventions. This inference will work with a number of common objects like arrays, Collection objects and ResultSets.
RuntimeExceptionattributes( string $field )
Get an associative array of other attributes for a field name.
$field arrayCake\View\Form\ContextInterface::attributes() entity( array|null $path null )
Fetch the leaf entity for the given path.
This method will traverse the given path and find the leaf entity. If the path does not contain a leaf entity false will be returned.
$path optional null Cake\Datasource\EntityInterface|Traversable|array|booleanRuntimeExceptionerror( string $field )
Get the errors for a given field
$field arrayCake\View\Form\ContextInterface::error() fieldNames( )
Get the field names from the top level entity.
If the context is for an array of entities, the 0th index will be used.
arrayCake\View\Form\ContextInterface::fieldNames() hasError( string $field )
Check whether or not a field has an error attached to it
$field booleanCake\View\Form\ContextInterface::hasError() isCreate( )
Check whether or not this form is a create or update.
If the context is for a single entity, the entity's isNew() method will be used. If isNew() returns null, a create operation will be assumed.
If the context is for a collection or array the first object in the collection will be used.
booleanCake\View\Form\ContextInterface::isCreate() isPrimaryKey( string $field )
Returns true if the passed field name is part of the primary key for this context
$field booleanCake\View\Form\ContextInterface::isPrimaryKey() isRequired( string $field )
Check if a field should be marked as required.
$field booleanCake\View\Form\ContextInterface::isRequired() primaryKey( )
Get the primary key data for the context.
Gets the primary key columns from the root entity's schema.
booleanCake\View\Form\ContextInterface::primaryKey() type( string $field )
Get the abstract field type for a given field name.
$field null|stringCake\Database\TypeCake\View\Form\ContextInterface::type() val( string $field )
Get the value for a given path.
Traverses the entity data and finds the value for $path.
$field mixedCake\View\Form\ContextInterface::val()
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.View.Form.EntityContext.html