Class Index
Base class for index.
A index in elastic search is approximately equivalent to a table or collection in a relational datastore. This ODM maps each index to a class.
Constants
Property Summary
-
$_connection protected
Cake\ElasticSearch\Datasource\ConnectionConnection instance
-
$_documentClass protected
stringThe name of the class that represent a single document for this type
-
$_eventClass protected
stringDefault class name for new event objects.
-
$_eventManager protected
Cake\Event\EventManagerInterface|Cake\Event\EventManagerInstance of the Cake\Event\EventManager this object is using to dispatch inner events.
-
$_name protected
stringThe name of the Elasticsearch index this class represents
-
$_registryAlias protected
stringRegistry key used to create this index object
-
$_rulesChecker protected
Cake\Datasource\RulesCheckerThe domain rules to be applied to entities saved by this table
-
$_schema protected
Cake\ElasticSearch\Datasource\MappingSchemaThe mapping schema for this type.
-
$_type protected
stringThe name of the Elasticsearch mapping type which this class represents
-
$_validatorClass protected
stringValidator class.
-
$_validators protected
Cake\Validation\Validator[]A list of validation objects indexed by name
-
$embeds protected
arrayCollection of Embedded sub documents this type has.
Method Summary
-
__construct() public
Constructor
-
alias() public deprecated
Get the alias for this Index.
-
buildRules() public
Returns a RulesChecker object after modifying the one that was supplied.
-
callFinder() public
Calls a finder method directly and applies it to the passed query, if no query is passed a new one will be created and returned
-
checkRules() public
Returns whether or not the passed entity complies with all the rules stored in the rules checker.
-
connection() public deprecated
Returns the connection instance or sets a new one
-
createValidator() protected
Creates a validator using a custom method inside your class.
-
defaultConnectionName() public static
The default connection name to inject when creating an instance.
-
delete() public
Delete a single entity.
-
deleteAll() public
Delete all matching records.
-
dispatchEvent() public
Wrapper for creating and dispatching events.
-
embedMany() public
Mark a property in documents of this type as list of embedded sub-documents.
-
embedOne() public
Mark a property in documents of this type as an embedded sub-document.
-
embedded() public
Get the list of embedded documents this type has.
-
entityClass() public deprecated
Returns the class used to hydrate documents for this index or sets a new one
-
eventManager() public deprecated
Returns the Cake\Event\EventManager manager instance for this object.
-
exists() public
Returns true if there is any record in this repository matching the specified conditions.
-
find() public
Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
-
findAll() public
Returns the query as passed
-
get() public
Returns a single record after finding it by its primary key, if no record is found this method throws an exception.
-
getAlias() public
Returns the type name.
-
getConnection() public
Returns the connection instance
-
getEntityClass() public
Returns the class used to hydrate document for this index.
-
getEventManager() public
Get the event manager for this Table.
-
getName() public
Returns the index name
-
getRegistryAlias() public
Returns the index registry key used to create this instance.
-
getSchema() public
Returns the index mapping object describing this index's properties.
-
getTable() public
Get the index name, as required by QueryTrait
-
getType() public
Returns the mapping type name
-
getValidator() public
Returns the validation rules tagged with $name. It is possible to have multiple different named validation sets, this is useful when you need to use varying rules when saving from different routines in your system.
-
hasField() public
Check whether or not a field exists in the mapping.
-
hasValidator() public
Checks whether or not a validator has been set.
-
implementedEvents() public
Get the callbacks this Index is interested in.
-
initialize() public
Initialize a index instance. Called after the constructor.
-
marshaller() public
Get a marshaller for this Index instance.
-
name() public deprecated
Returns the index name or sets a new one
-
newEntities() public
Create a list of entities + associated entities from an array.
-
newEntity() public
Create a new entity + associated entities from an array.
-
patchEntities() public
Merges each of the elements passed in
$datainto the entities found in$entitiesrespecting the accessible fields configured on the entities. Merging is done by matching the primary key in each of the elements in$dataand$entities. -
patchEntity() public
Merges the passed
$datainto$entityrespecting the accessible fields configured on the entity. Returns the same entity after being altered. -
query() public
Creates a new Query instance for this repository
-
rulesChecker() public
Returns the RulesChecker for this instance.
-
save() public
Persists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.
-
saveMany() public
Persists a list of entities based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error. Triggers the
Model.beforeSaveandModel.afterSaveevents.Options
checkRulesDefaults to true. Check deletion rules before deleting the record.
-
schema() public deprecated
Returns the index mapping object describing this index's properties.
-
setAlias() public
Sets the index alias.
-
setConnection() public
Sets the connection instance
-
setEntityClass() public
Sets the class used to hydrate documents for this index.
-
setEventManager() public
Returns the Cake\Event\EventManager manager instance for this object.
-
setName() public
Sets the index name
-
setRegistryAlias() public
Sets the index registry key used to create this index instance.
-
setSchema() public
Sets the index mapping object describing this index's properties.
-
setType() public
Sets the mapping type name
-
setValidator() public
This method stores a custom validator under the given name.
-
table() public deprecated
Get the index name, as required by QueryTrait
-
updateAll() public
Update all matching records.
-
validationDefault() public
Returns the default validator object. Subclasses can override this function to add a default validation set to the validator object.
-
validationMethodExists() protected
Checks if validation method exists.
-
validator() public deprecated
Returns the validation rules tagged with $name. It is possible to have multiple different named validation sets, this is useful when you need to use varying rules when saving from different routines in your system.
Method Detail
__construct() ¶ public
__construct(array $config = [])
Constructor
Options
- connection: The Elastica instance.
- name: The name of the index. If this isn't set the name will be inferred from the class name.
- type: The name of type mapping used. If this ins't set, the type will be equal to 'name'.
- eventManager: Used to inject a specific eventmanager.
At the end of the constructor the Model.initialize event will be triggered.
Parameters
-
array$config optional The configuration options, see above.
alias() ¶ public
alias(string|null $alias = null): string
Get the alias for this Index.
This method is just an alias of name().
Parameters
-
string|null$alias optional The new index name
Returns
stringbuildRules() ¶ public
buildRules(Cake\Datasource\RulesChecker $rules): Cake\Datasource\RulesChecker
Returns a RulesChecker object after modifying the one that was supplied.
Subclasses should override this method in order to initialize the rules to be applied to entities saved by this instance.
Parameters
-
Cake\Datasource\RulesChecker$rules The rules object to be modified.
Returns
Cake\Datasource\RulesCheckercallFinder() ¶ public
callFinder(string $type, Cake\ElasticSearch\Query $query, array $options = []): Cake\ElasticSearch\Query
Calls a finder method directly and applies it to the passed query, if no query is passed a new one will be created and returned
Parameters
-
string$type name of the finder to be called
-
Cake\ElasticSearch\Query$query The query object to apply the finder options to
-
array$options optional List of options to pass to the finder
Returns
Cake\ElasticSearch\QueryThrows
BadMethodCallExceptioncheckRules() ¶ public
checkRules(Cake\Datasource\EntityInterface $entity, string $operation = RulesChecker::CREATE, ArrayObject|array|null $options = null): bool
Returns whether or not the passed entity complies with all the rules stored in the rules checker.
Parameters
-
Cake\Datasource\EntityInterface$entity The entity to check for validity.
-
string$operation optional The operation being run. Either 'create', 'update' or 'delete'.
-
ArrayObject|array|null$options optional The options To be passed to the rules.
Returns
boolconnection() ¶ public
connection(Cake\ElasticSearch\Datasource\Connection $conn = null): Cake\ElasticSearch\Datasource\Connection
Returns the connection instance or sets a new one
Parameters
-
Cake\ElasticSearch\Datasource\Connection$conn optional the new connection instance
Returns
Cake\ElasticSearch\Datasource\ConnectioncreateValidator() ¶ protected
createValidator(string $name): Cake\Validation\Validator
Creates a validator using a custom method inside your class.
This method is used only to build a new validator and it does not store it in your object. If you want to build and reuse validators, use getValidator() method instead.
Parameters
-
string$name The name of the validation set to create.
Returns
Cake\Validation\ValidatorThrows
RuntimeExceptiondefaultConnectionName() ¶ public static
defaultConnectionName(): string
The default connection name to inject when creating an instance.
Returns
stringdelete() ¶ public
delete(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): bool
Delete a single entity.
Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association.
Triggers the Model.beforeDelete and Model.afterDelete events.
Parameters
-
Cake\Datasource\EntityInterface$entity The entity to remove.
-
array|ArrayAccess$options optional The options for the delete.
Returns
boolsuccess
deleteAll() ¶ public
deleteAll(mixed $conditions): bool
Delete all matching records.
Deletes all records matching the provided conditions.
This method will not trigger beforeDelete/afterDelete events. If you need those first load a collection of records and delete them.
Parameters
-
mixed$conditions An array of conditions, similar to those used with find()
Returns
boolSuccess Returns true if one or more documents are effected.
See Also
dispatchEvent() ¶ public
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\Event
Wrapper for creating and dispatching events.
Returns a dispatched event.
Parameters
-
string$name Name of the event.
-
array|null$data optional Any value you wish to be transported with this event to it can be read by listeners.
-
object|null$subject optional The object that this event applies to ($this by default).
Returns
Cake\Event\EventembedMany() ¶ public
embedMany(string $name, array $options = []): void
Mark a property in documents of this type as list of embedded sub-documents.
Embedded documents are converted into instances of the named document type. This allows you to attach entity level behavior to subsections of your documents.
This method will make a list of embedded documents from the named property.
Parameters
-
string$name The name of the property that contains the embedded document.
-
array$options optional The options for the embedded document.
Returns
voidembedOne() ¶ public
embedOne(string $name, array $options = []): void
Mark a property in documents of this type as an embedded sub-document.
Embedded documents are converted into instances of the named document type. This allows you to attach entity level behavior to subsections of your documents.
Parameters
-
string$name The name of the property that contains the embedded document.
-
array$options optional The options for the embedded document.
Returns
voidembedded() ¶ public
embedded(): array
Get the list of embedded documents this type has.
Returns
arrayentityClass() ¶ public
entityClass(string $name = null): string
Returns the class used to hydrate documents for this index or sets a new one
Parameters
-
string$name optional the name of the class to use
Returns
stringThrows
Cake\ElasticSearch\MissingDocumentExceptionwhen the document class cannot be found
eventManager() ¶ public
eventManager(Cake\Event\EventManager|null $eventManager = null): Cake\Event\EventManager
Returns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Parameters
-
Cake\Event\EventManager|null$eventManager optional the eventManager to set
Returns
Cake\Event\EventManagerexists() ¶ public
exists(array|ArrayAccess $conditions): bool
Returns true if there is any record in this repository matching the specified conditions.
Parameters
-
array|ArrayAccess$conditions list of conditions to pass to the query
Returns
boolfind() ¶ public
find(string $type = 'all', array|ArrayAccess $options = []): Cake\ElasticSearch\Query
Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
Model.beforeFind event
Each find() will trigger a Model.beforeFind event for all attached
listeners. Any listener can set a valid result set using $query
Parameters
-
string$type optional the type of query to perform
-
array|ArrayAccess$options optional An array that will be passed to Query::applyOptions
Returns
Cake\ElasticSearch\QueryfindAll() ¶ public
findAll(Cake\ElasticSearch\Query $query, array $options = []): Cake\ElasticSearch\Query
Returns the query as passed
Parameters
-
Cake\ElasticSearch\Query$query An Elasticsearch query object
-
array$options optional An array of options to be used for query logic
Returns
Cake\ElasticSearch\Queryget() ¶ public
get(mixed $primaryKey, array|ArrayAccess $options = []): Cake\ElasticSearch\Document
Returns a single record after finding it by its primary key, if no record is found this method throws an exception.
Any key present in the options array will be translated as a GET argument when getting the document by its id. This is often useful whe you need to specify the parent or routing.
This method will not trigger the Model.beforeFind callback as it does not use queries for the search, but a faster key lookup to the search index.
Parameters
-
mixed$primaryKey The document's primary key
-
array|ArrayAccess$options optional An array of options
Returns
Cake\ElasticSearch\DocumentA new Elasticsearch document entity
Throws
Elastica\Exception\NotFoundExceptionif no document exist with such id
getConnection() ¶ public
getConnection(): Cake\ElasticSearch\Datasource\Connection
Returns the connection instance
Returns
Cake\ElasticSearch\Datasource\ConnectiongetEntityClass() ¶ public
getEntityClass(): string
Returns the class used to hydrate document for this index.
Returns
stringgetEventManager() ¶ public
getEventManager(): Cake\Event\EventManager
Get the event manager for this Table.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Returns
Cake\Event\EventManagergetName() ¶ public
getName(): string
Returns the index name
If this isn't set the name will be inferred from the class name
Returns
stringgetRegistryAlias() ¶ public
getRegistryAlias(): string
Returns the index registry key used to create this instance.
Returns
stringgetSchema() ¶ public
getSchema(): Cake\ElasticSearch\Datasource\MappingSchema
Returns the index mapping object describing this index's properties.
This will fetch the schema from Elasticsearch the first time this method is called.
Returns
Cake\ElasticSearch\Datasource\MappingSchemagetTable() ¶ public
getTable(): string
Get the index name, as required by QueryTrait
This method is just an alias of name().
Returns
stringgetType() ¶ public
getType(): string
Returns the mapping type name
If not defined, use the same as index name
Returns
stringgetValidator() ¶ public
getValidator(string|null $name = null): Cake\Validation\Validator
Returns the validation rules tagged with $name. It is possible to have multiple different named validation sets, this is useful when you need to use varying rules when saving from different routines in your system.
If a validator has not been set earlier, this method will build a valiator using a method inside your class.
For example, if you wish to create a validation set called 'forSubscription', you will need to create a method in your Table subclass as follows:
public function validationForSubscription($validator)
{
return $validator
->add('email', 'valid-email', ['rule' => 'email'])
->add('password', 'valid', ['rule' => 'notBlank'])
->requirePresence('username');
}
$validator = $this->getValidator('forSubscription');
You can implement the method in validationDefault in your Table subclass
should you wish to have a validation set that applies in cases where no other
set is specified.
If a $name argument has not been provided, the default validator will be returned.
You can configure your default validator name in a DEFAULT_VALIDATOR
class constant.
Parameters
-
string|null$name optional The name of the validation set to return.
Returns
Cake\Validation\ValidatorhasField() ¶ public
hasField(string $field): bool
Check whether or not a field exists in the mapping.
Parameters
-
string$field The field to check.
Returns
boolhasValidator() ¶ public
hasValidator(string $name): bool
Checks whether or not a validator has been set.
Parameters
-
string$name The name of a validator.
Returns
boolimplementedEvents() ¶ public
implementedEvents(): array
Get the callbacks this Index is interested in.
By implementing the conventional methods a Index class is assumed to be interested in the related event.
Override this method if you need to add non-conventional event listeners. Or if you want you index to listen to non-standard events.
The conventional method map is:
- Model.beforeMarshal => beforeMarshal
- Model.beforeFind => beforeFind
- Model.beforeSave => beforeSave
- Model.afterSave => afterSave
- Model.beforeDelete => beforeDelete
- Model.afterDelete => afterDelete
- Model.beforeRules => beforeRules
- Model.afterRules => afterRules
Returns
arrayinitialize() ¶ public
initialize(array $config): void
Initialize a index instance. Called after the constructor.
You can use this method to define embedded documents, define validation and do any other initialization logic you need.
public function initialize(array $config)
{
$this->embedMany('Comments');
}
Parameters
-
array$config Configuration options passed to the constructor
Returns
voidmarshaller() ¶ public
marshaller(): Cake\ElasticSearch\Marshaller
Get a marshaller for this Index instance.
Returns
Cake\ElasticSearch\Marshallername() ¶ public
name(string $name = null): string
Returns the index name or sets a new one
Parameters
-
string$name optional the new index name
Returns
stringnewEntities() ¶ public
newEntities(array $data, array $options = []): array
Create a list of entities + associated entities from an array.
This is most useful when hydrating request data back into entities. For example, in your controller code:
$articles = $this->Articles->newEntities($this->request->data());
The hydrated entities can then be iterated and saved.
Parameters
-
array$data The data to build an entity with.
-
array$options optional A list of options for the objects hydration.
Returns
arrayAn array of hydrated records.
newEntity() ¶ public
newEntity(array|null $data = null, array $options = []): Cake\Datasource\EntityInterface
Create a new entity + associated entities from an array.
This is most useful when hydrating request data back into entities. For example, in your controller code:
$article = $this->Articles->newEntity($this->request->data());
The hydrated entity will correctly do an insert/update based on the primary key data existing in the database when the entity is saved. Until the entity is saved, it will be a detached record.
Parameters
-
array|null$data optional The data to build an entity with.
-
array$options optional A list of options for the object hydration.
Returns
Cake\Datasource\EntityInterfacepatchEntities() ¶ public
patchEntities(Cake\Datasource\EntityInterface[]|Traversable $entities, array $data, array $options = []): array
Merges each of the elements passed in $data into the entities
found in $entities respecting the accessible fields configured on the entities.
Merging is done by matching the primary key in each of the elements in $data
and $entities.
This is most useful when editing a list of existing entities using request data:
$article = $this->Articles->patchEntities($articles, $this->request->data());
Parameters
-
Cake\Datasource\EntityInterface[]|Traversable$entities the entities that will get the data merged in
-
array$data list of arrays to be merged into the entities
-
array$options optional A list of options for the objects hydration.
Returns
arraypatchEntity() ¶ public
patchEntity(Cake\Datasource\EntityInterface $entity, array $data, array $options = []): Cake\Datasource\EntityInterface
Merges the passed $data into $entity respecting the accessible
fields configured on the entity. Returns the same entity after being
altered.
This is most useful when editing an existing entity using request data:
$article = $this->Articles->patchEntity($article, $this->request->data());
Parameters
-
Cake\Datasource\EntityInterface$entity the entity that will get the data merged in
-
array$data key value list of fields to be merged into the entity
-
array$options optional A list of options for the object hydration.
Returns
Cake\Datasource\EntityInterfacequery() ¶ public
query(): Cake\ElasticSearch\Query
Creates a new Query instance for this repository
Returns
Cake\ElasticSearch\QueryrulesChecker() ¶ public
rulesChecker(): Cake\Datasource\RulesChecker
Returns the RulesChecker for this instance.
A RulesChecker object is used to test an entity for validity on rules that may involve complex logic or data that needs to be fetched from relevant datasources.
Returns
Cake\Datasource\RulesCheckerSee Also
save() ¶ public
save(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): Cake\Datasource\EntityInterface|bool
Persists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.
Triggers the Model.beforeSave and Model.afterSave events.
Options
checkRulesDefaults to true. Check deletion rules before deleting the record.
Parameters
-
Cake\Datasource\EntityInterface$entity The entity to be saved
-
array|ArrayAccess$options optional An array of options to be used for the event
Returns
Cake\Datasource\EntityInterface|boolsaveMany() ¶ public
saveMany(array $entities, array $options = []): bool
Persists a list of entities based on the fields that are marked as dirty and
returns the same entity after a successful save or false in case
of any error.
Triggers the Model.beforeSave and Model.afterSave events.
Options
checkRulesDefaults to true. Check deletion rules before deleting the record.
Parameters
-
array$entities An array of entities
-
array$options optional An array of options to be used for the event
Returns
boolschema() ¶ public
schema(array|Cake\ElasticSearch\Datasource\MappingSchema|null $schema = null): Cake\ElasticSearch\Datasource\MappingSchema
Returns the index mapping object describing this index's properties.
If a MappingSchema is passed, it will be used for this index instead of the default one.
If an array is passed, a new MappingSchema will be constructed out of it and used as the schema for this index.
Parameters
-
array|Cake\ElasticSearch\Datasource\MappingSchema|null$schema optional New schema to be used for this index
Returns
Cake\ElasticSearch\Datasource\MappingSchemasetAlias() ¶ public
setAlias(string $alias): $this
Sets the index alias.
Parameters
-
string$alias Index alias
Returns
$thissetConnection() ¶ public
setConnection(Cake\ElasticSearch\Datasource\Connection $conn): $this
Sets the connection instance
Parameters
-
Cake\ElasticSearch\Datasource\Connection$conn the new connection instance
Returns
$thissetEntityClass() ¶ public
setEntityClass(string $name): $this
Sets the class used to hydrate documents for this index.
Parameters
-
string$name The name of the class to use
Returns
$thisThrows
Cake\ElasticSearch\MissingDocumentExceptionwhen the document class cannot be found
setEventManager() ¶ public
setEventManager(Cake\Event\EventManager $eventManager): $this
Returns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
Parameters
-
Cake\Event\EventManager$eventManager the eventManager to set
Returns
$thissetName() ¶ public
setName(string $name): $this
Sets the index name
Parameters
-
string$name Index name
Returns
$thissetRegistryAlias() ¶ public
setRegistryAlias(string $registryAlias): $this
Sets the index registry key used to create this index instance.
Parameters
-
string$registryAlias The key used to access this object.
Returns
$thissetSchema() ¶ public
setSchema(array|Cake\ElasticSearch\Datasource\MappingSchema $schema): $this
Sets the index mapping object describing this index's properties.
If an array is passed, a new MappingSchema will be constructed out of it and used as the schema for this index.
Parameters
-
array|Cake\ElasticSearch\Datasource\MappingSchema$schema Schema to be used for this index
Returns
$thissetType() ¶ public
setType(string $type): $this
Sets the mapping type name
Parameters
-
string$type Mapping type name
Returns
$thissetValidator() ¶ public
setValidator(string $name, Cake\Validation\Validator $validator): $this
This method stores a custom validator under the given name.
You can build the object by yourself and store it in your object:
$validator = new \Cake\Validation\Validator($table);
$validator
->add('email', 'valid-email', ['rule' => 'email'])
->add('password', 'valid', ['rule' => 'notBlank'])
->allowEmpty('bio');
$this->setValidator('forSubscription', $validator);
Parameters
-
string$name The name of a validator to be set.
-
Cake\Validation\Validator$validator Validator object to be set.
Returns
$thistable() ¶ public
table(): string
Get the index name, as required by QueryTrait
This method is just an alias of name().
Returns
stringupdateAll() ¶ public
updateAll(string|array|callable|Cake\Database\Expression\QueryExpression $fields, mixed $conditions): void
Update all matching records.
Sets the $fields to the provided values based on $conditions. This method will not trigger beforeSave/afterSave events. If you need those first load a collection of records and update them.
Parameters
-
string|array|callable|Cake\Database\Expression\QueryExpression$fields A hash of field => new value.
-
mixed$conditions An array of conditions, similar to those used with find()
Returns
voidvalidationDefault() ¶ public
validationDefault(Cake\Validation\Validator $validator): Cake\Validation\Validator
Returns the default validator object. Subclasses can override this function to add a default validation set to the validator object.
Parameters
-
Cake\Validation\Validator$validator The validator that can be modified to add some rules to it.
Returns
Cake\Validation\ValidatorvalidationMethodExists() ¶ protected
validationMethodExists(string $name): bool
Checks if validation method exists.
Parameters
-
string$name Validation method name.
Returns
boolvalidator() ¶ public
validator(string|null $name = null, Cake\Validation\Validator|null $validator = null): Cake\Validation\Validator
Returns the validation rules tagged with $name. It is possible to have multiple different named validation sets, this is useful when you need to use varying rules when saving from different routines in your system.
There are two different ways of creating and naming validation sets: by creating a new method inside your own Table subclass, or by building the validator object yourself and storing it using this method.
For example, if you wish to create a validation set called 'forSubscription', you will need to create a method in your Table subclass as follows:
public function validationForSubscription($validator)
{
return $validator
->add('email', 'valid-email', ['rule' => 'email'])
->add('password', 'valid', ['rule' => 'notBlank'])
->requirePresence('username');
}
Otherwise, you can build the object by yourself and store it in the Table object:
$validator = new \Cake\Validation\Validator($table);
$validator
->add('email', 'valid-email', ['rule' => 'email'])
->add('password', 'valid', ['rule' => 'notBlank'])
->allowEmpty('bio');
$table->setValidator('forSubscription', $validator);
You can implement the method in validationDefault in your Table subclass
should you wish to have a validation set that applies in cases where no other
set is specified.
Parameters
-
string|null$name optional the name of the validation set to return
-
Cake\Validation\Validator|null$validator optional The validator instance to store, use null to get a validator.
Returns
Cake\Validation\ValidatorThrows
RuntimeExceptionProperty Detail
$_documentClass ¶ protected
The name of the class that represent a single document for this type
Type
string$_eventManager ¶ protected
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Type
Cake\Event\EventManagerInterface|Cake\Event\EventManager$_rulesChecker ¶ protected
The domain rules to be applied to entities saved by this table
Type
Cake\Datasource\RulesChecker$_schema ¶ protected
The mapping schema for this type.
Type
Cake\ElasticSearch\Datasource\MappingSchema$_type ¶ protected
The name of the Elasticsearch mapping type which this class represents
For default, the mapping type is equal to index name for easy use.
Type
string$_validators ¶ protected
A list of validation objects indexed by name
Type
Cake\Validation\Validator[]