Skip to content

Instantly share code, notes, and snippets.

@LubosRemplik
Created February 14, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LubosRemplik/88b8dcfe0c26a25baa6af2d7c0a1f4b0 to your computer and use it in GitHub Desktop.
Save LubosRemplik/88b8dcfe0c26a25baa6af2d7c0a1f4b0 to your computer and use it in GitHub Desktop.
Crud many-to-many save issue - edit method + request data
/**
* Method: edit
*
* Amend user entity before save
*
* {@inheritDoc}
*/
public function edit($id)
{
if ($this->request->is('put')) {
debug($this->request->getData());
die;
}
// set dirty password false when empty
$this->Crud->on('beforeSave', function (Event $event) {
if (empty($event->getSubject()->entity->password)) {
$event->getSubject()->entity->setDirty('password', false);
}
});
return $this->Crud->execute();
}
// Request data debug
[
'email' => 'okon.curtis@botsford.biz',
'first_name' => 'Vladimir',
'last_name' => 'Rowe',
'roles' => [
'_ids' => [
(int) 0 => '2',
(int) 1 => '1',
(int) 2 => '3',
(int) 3 => '6'
]
],
'tags' => '',
'status' => '1',
'password' => ''
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment