我注意到在4.1中有新的afterMarshal事件。把它放在哪里?在表模式?以及如何?我想做一些工作的结果,每次它的加载。多谢帮忙
3b6akqbq1#
用于通过“CAKEPHP 4”中的模型进行加密和解密
public $encryptedFields = ['first_name','last_name']; public function beforeSave($event, $entity, $options) { foreach($this->encryptedFields as $fieldName) { if($entity->has($fieldName)) { $entity->set($fieldName, encodeBeforeSave($entity->get($fieldName)));} } return true; } public function beforeFind( $event, $query, $options) { $query->formatResults( function ($results) { return $results->map(function ($row){ foreach($this->encryptedFields as $fieldName) { if(isset($row[$fieldName]) && !empty($row[$fieldName]) ) { $row[$fieldName] = decodeBeforefind($row[$fieldName]); } } return $row; }); } ); }
1条答案
按热度按时间3b6akqbq1#
用于通过“CAKEPHP 4”中的模型进行加密和解密