私は現実のセッターによってフィールドが変更されていて、フィールドが正しく更新されています。save()
保存された値は、返されたものではなく、私のセッターの中間で計算された値です(以下のコードを参照してください)。CakePHP3.2:save()は、セッターによってフィールドが変わっても変わっていません
unlock_keyは、varchar(255)utf8_general_ciフィールドです。
モデルは次のとおりです。
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);
}
....
}
そして、私のコードは次のとおりです。
$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)
出力は次のとおりです。
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'
}
のでsave()
た後、私はパディング文字でnot encrypted string
を踏襲していますDB。
なぜですか?