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.array<string> ['length', 'precision', 'comment', 'null', 'default']
array<string, mixed>Context data for this object.
boolBoolean to track whether the entity is a collection.
stringThe name of the top level entity/table object.
Cake\ORM\Locator\LocatorInterface|nullTable locator instance
arrayCake\ORM\Table>A dictionary of tables
arrayCake\Validation\Validator>Dictionary of validators.
string|nullThis object's default table alias.
Constructor.
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
Read property values or traverse arrays/iterators.
Get the table instance from a property path
Get the validator associated to an entity based on naming conventions.
Prepare some additional data from the context.
Get default value from table schema for given entity field.
Get an associative array of other attributes for a field name.
Fetch the entity or data value for a given path
Get the errors for a given field
Convenience method to get a table instance.
Get the field names from the top level entity.
Get field length from validation
Get the primary key data for the context.
Gets the default "required" error message for a field
Gets the table locator.
Check whether a field has an error attached to it
Check whether this form is a create or update.
Returns true if the passed field name is part of the primary key for this context
Check if a field should be marked as required.
Fetch the terminal or leaf entity for the given path.
Get the primary key data for the context.
Sets the table locator.
Get the abstract field type for a given field name.
Get the value for a given path.
__construct(array<string, mixed> $context)
Constructor.
array<string, mixed> $context Context info.
_extractMultiple(mixed $values, array<string> $path): array|null
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
mixed $values The list from which to extract primary keys from
array<string> $path Each one of the parts in a path for a field name
array|null_getProp(mixed $target, string $field): mixed
Read property values or traverse arrays/iterators.
mixed $target The entity/array/collection to fetch $field from.
string $field The next field to fetch.
mixed_getTable(Cake\Datasource\EntityInterface|array<string>|string $parts, bool $fallback = true): Cake\ORM\Table|null
Get the table instance from a property path
Cake\Datasource\EntityInterface|array<string>|string $parts Each one of the parts in a path for a field name
bool $fallback optional Whether to fallback to the last found table when a nonexistent field/property is being encountered.
Cake\ORM\Table|null_getValidator(array $parts): Cake\Validation\Validator
Get the validator associated to an entity based on naming conventions.
array $parts Each one of the parts in a path for a field name
Cake\Validation\ValidatorRuntimeException_prepare(): void
Prepare some additional data from the context.
If the table option was provided to the constructor and it was a string, TableLocator 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.
voidRuntimeException_schemaDefault(array<string> $parts): mixed
Get default value from table schema for given entity field.
array<string> $parts Each one of the parts in a path for a field name
mixedattributes(string $field): array
Get an associative array of other attributes for a field name.
string $field A dot separated path to get additional data on.
arrayentity(array|null $path = null): Cake\Datasource\EntityInterface|iterable|null
Fetch the entity or data value for a given path
This method will traverse the given path and find the entity or array value for a given path.
If you only want the terminal Entity for a path use leafEntity instead.
array|null $path optional Each one of the parts in a path for a field name or null to get the entity passed in constructor context.
Cake\Datasource\EntityInterface|iterable|nullRuntimeExceptionerror(string $field): array
Get the errors for a given field
string $field A dot separated path to check errors on.
arrayfetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table
Convenience method to get a table instance.
string|null $alias optional The alias name you want to get. Should be in CamelCase format. If null then the value of $defaultTable property is used.
array<string, mixed> $options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Cake\ORM\TableCake\Core\Exception\CakeExceptionfieldNames(): array<string>
Get the field names from the top level entity.
If the context is for an array of entities, the 0th index will be used.
array<string>getMaxLength(string $field): int|null
Get field length from validation
string $field The dot separated path to the field you want to check.
int|nullgetPrimaryKey(): array<string>
Get the primary key data for the context.
Gets the primary key columns from the root entity's schema.
array<string>getRequiredMessage(string $field): string|null
Gets the default "required" error message for a field
string $field string|nullgetTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Cake\ORM\Locator\LocatorInterfacehasError(string $field): bool
Check whether a field has an error attached to it
string $field A dot separated path to check errors on.
boolisCreate(): bool
Check whether 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.
boolisPrimaryKey(string $field): bool
Returns true if the passed field name is part of the primary key for this context
string $field boolisRequired(string $field): bool|null
Check if a field should be marked as required.
In this context class, this is simply defined by the 'required' array.
string $field The dot separated path to the field you want to check.
bool|nullleafEntity(array|null $path = null): array
Fetch the terminal or leaf entity for the given path.
Traverse the path until an entity cannot be found. Lists containing entities will be traversed if the first element contains an entity. Otherwise, the containing Entity will be assumed to be the terminal one.
array|null $path optional Each one of the parts in a path for a field name or null to get the entity passed in constructor context.
arrayRuntimeExceptionprimaryKey(): array<string>
Get the primary key data for the context.
Gets the primary key columns from the root entity's schema.
array<string>setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Cake\ORM\Locator\LocatorInterface $tableLocator LocatorInterface instance.
$thistype(string $field): string|null
Get the abstract field type for a given field name.
string $field A dot separated path to get a schema type for.
string|nullval(string $field, array<string, mixed> $options = []): mixed
Get the value for a given path.
Traverses the entity data and finds the value for $path.
string $field The dot separated path to the value.
array<string, mixed> $options optional Options:
mixedContext data for this object.
array<string, mixed>Boolean to track whether the entity is a collection.
boolThe name of the top level entity/table object.
stringTable locator instance
Cake\ORM\Locator\LocatorInterface|nullA dictionary of tables
arrayCake\ORM\Table>Dictionary of validators.
arrayCake\Validation\Validator>This object's default table alias.
string|null
© 2005–present 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.
https://api.cakephp.org/4.4/class-Cake.View.Form.EntityContext.html