Skip to content
Advertisement

how to update a single attribute of an item in a table using CakePHP

I’m trying to update only one piece of information from a user saved in the database, and cakephp accepts an array of values for each attribute, but I don’t have values for other attributes and cakephp will not update the row because it is expecting all the values found in the row.

Advertisement

Answer

First Way : Create new a Query object using query():

JavaScript

http://book.cakephp.org/3.0/en/orm/query-builder.html


Second Way: Using PatchEntity


using the fieldList() option when creating or merging data into an entity:

this will allow you to only update or insert field u want

JavaScript

http://book.cakephp.org/3.0/en/orm/saving-data.html#changing-accessible-fields

http://book.cakephp.org/3.0/en/orm/query-builder.html#updating-data

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement