// Both inserts and updates are performed
protected function _before_write(&$data){
	if($data['user_birthday']) {$data['user_constellation']=\birthday2constellation($data['user_birthday']);// Change your birthday sign
		$data['user_animal']=\birthday2animal($data['user_birthday']);	// Change of birthday to Chinese zodiac}}// Execute only when inserting
protected function _before_write(&$data.$options){
	if($data['user_birthday']) {$data['user_constellation']=\birthday2constellation($data['user_birthday']);
		$data['user_animal']=\birthday2animal($data['user_birthday']); }}// Execute only when updating
protected function _before_write(&$data.$options){
	if($data['user_birthday']) {$data['user_constellation']=\birthday2constellation($data['user_birthday']);
		$data['user_animal']=\birthday2animal($data['user_birthday']); }}// Execute after insertion
protected function _after_insert($data.$options){
	$updateData= [];$updateData['user_no'] ='520'.\str_pad($data['user_id'].5.0,\STR_PAD_LEFT);
	$this
		->where(['user_id'= >$data['user_id']])
		->save($updateData);
	// update `user` set user_no=concat('520',lpad(user_id,5,'0'))
}
Copy the code