I’m looking for help with sending back temporary information to the controller for display. Works in CakePHP2, looking to replicate in CakePHP4
I have an option, when editing a user, to set a temporary password. If a check box is set then in the beforeSave we create a random password and set the entity;
if ($entity->_randomPassword == true) {
// Generate password in Office 365 style (Abb00000)
$password = $this->_randomPassword(1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$password .= $this->_randomPassword(2, 'abcdefghijklmnopqrstuvwxyz');
$password .= $this->_randomPassword(5, '0123456789');
$entity->password = $password;
}
All works fine, but I need to pass this random password back to display it on screen. In CakePHP2 we’d just temporarily set in the beforeSave
$this->rawPassword = $password; # Temporarily expose raw password for display
Then access it in the controller
if ($this->MemberPermission->save($this->request->data)) {
if (isset($this->MemberPermission->rawPassword) === true) {
$this->Flash->success('The permissions have been saved. The new password is: ' . $this->MemberPermission->rawPassword);
Sadly not quite this easy in CakePHP4