Issue
I have table Users that has telephone field.
The problem is if I want to seperate user telephone number into 2 textboxes when showing user information and vice versa when User submits form, auto merges them into one value before patchEntity() and save() to database.
Can CakePHP make it nice and easy using CakePhp Form Helper?
Thanks.
Solution
You can use Model.beforeMarshal
event to modify , restructure request data before patching entitiy , The beforMarshal
event is triggered just before the validation process.
For example , to concatenate two form values to one you can do following
// In a table or behavior class
public function beforeMarshal(Event $event, $data)
{
$data['telephone'] = $data['telephone_1'].' '. $data['telephone_2'];
}
Do not forget to add this statement use Cake\Event\Event;
at the top of your table or behavior class.
For more info about Model.beforeMarshal
see http://book.cakephp.org/3.0/en/orm/saving-data.html#modifying-request-data-before-building-entities
Answered By - N Nem
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.