CakePHP3:如何在保存到数据库时自动转换十进制(货币)字段?

CakePHP3: How to automate the conversion of decimal (money) fields when saving to the database?

我正在为巴西用户开发一个网站。前端的所有货币字段都使用模式 1.234,56。为此,我使用 mask.js 插件和掩码 $('.mask-dinheiro').mask("000.000.000.000,00", {reverse: true});

这个项目刚开始,所以我要在控制器上逐字段转换为 MySQL 通用模式 (1234.56)。但是有没有办法使这种转换隐含在数据库中保存数据?我已经在 config/app.php 上设置了 'defaultLocale' => env('APP_DEFAULT_LOCALE', 'pt_BR'),但这并不能满足我的要求

Create a Behavior, then add a beforeSave() or beforeMarshall() 转换任何需要转换的字段。