Created
February 14, 2018 08:30
-
-
Save LubosRemplik/88b8dcfe0c26a25baa6af2d7c0a1f4b0 to your computer and use it in GitHub Desktop.
Crud many-to-many save issue - edit method + request data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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