To get the identifier of the newly created registration cakePHP 3.x, it's very simple, just check if the entity was saved well, otherwise you will not have access to the identifier.
The code is very simple
$this->loadModel('ModelName');
$newEntity = $this->ModelName->newEntity();
So after loading your model and declaring a new record, you can put the values on the entity before saving it.
For example if it's a post request, you can do:
To proceed fields by fields:
$newEntity->name = $this->request->getData('name');
or (according to cakePHP version, first example is from the recent version)
$newEntity->name = $this->request->data('name');
Otherwise globally, in this case the name attributes of your fields in the form must be identical to the attributes of your entity in database.
$newEntity = $this->ModalName->patchEntity($newEntity, $this->request->getData());
And once the entity is ready, you will only have access to its identifier if it is registered in the database.
Solution to get the ID of the last record, you have to do this:
if($this->ModalName->save($newEntity) {
//you can get ID here
$id = $newEntity->id;
}
I hope it will be useful.