how to prevent updating a field in CakePHP 3 beforesave()?

376 views Asked by At

In my form, if an input field is not changed, I don't want to update that particular field in database. How can I achieve this in beforesave() ? I tried $entity->unset($fieldName); but that doesn't work.

UPDATE: In my form, for one filed, I am saving encrypted data in database, and in beforeFind(), if this field is not null in database, this input is set to "*** ***". My encryption code for this field is in beforeSave(). I want to update this field only if it is not "*** ***".

1

There are 1 answers

0
web_developer On

my code is working fine when $entity->unset($fieldName); changed tounset($entity->$fieldName);