Ich bin mit einer seltsamen Situation konfrontiert, wo ich ein Feld von einem funktionierenden Setter, der korrekt in der Entität aktualisiert wird, aber wenn ich save()
aufrufen , der gespeicherte Wert ist derjenige, der in der Mitte meines Setter berechnet wurde (siehe im folgenden Code) und nicht der zurückgegebene!?!CakePHP3.2: save() bleibt seltsamerweise ein Feld von einem Setter
unlock_key ist ein varchar (255) utf8_general_ci Feld.
Das Modell ist:
class Agtheme extends Entity {
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
...
'unlock_key' => true,
...
];
protected function _setUnlockKey($data) {
if (empty($data)) {
return '';
}
$AESEncryption = Configure::read('AESEncryption');
if(32 !== strlen($AESEncryption['password'])) $secret = hash('SHA256', $AESEncryption['password'], true);
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding); // !!!! Here is the value I find in my DB !!!!
$encrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secret, $data, MCRYPT_MODE_CBC, str_repeat("\0", 16));
return base64_encode($encrypt);
}
....
}
Und Mein Code ist:
$agTheme->unlock_key = 'not encrypted string';
debug($agTheme); // The output is below
if (!$this->Agthemes->save($agTheme)) {
debug($agTheme); // I don't come here.
die('Error');
}
die();
debug($agTheme)
Ausgabe lautet:
object(App\Model\Entity\Agtheme) {
'id' => (int) 1,
....,
'unlock_key' => 'QCXW7ksUpdmH6QfVua62DUDbHjLcvUF38MAneG9KGKo=', // this value is the one I want to see in my DB
....,
'[new]' => false,
'[accessible]' => [
....,
'unlock_key' => true,
....,
],
'[dirty]' => [
'unlock_key' => true
],
'[original]' => [
'unlock_key' => null
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Agthemes'
}
So nach save()
habe ich not encrypted string
durch padding Zeichen in die DB.
Warum ??