Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2. Many inputs for one Model/DB field

How such inputs could be translated into DATE field in DB?

enter image description here

Customer insisted on such way to input user birthdate. First my thought was simply to concat in one field in beforeValidate, but after this inputs won't be able to display date, that was inputed, from the DB. How to avoid such restriction?

like image 677
D.R. Avatar asked Dec 09 '25 14:12

D.R.


1 Answers

  1. Add these 3 fields as virtual properties in the model class.
  2. In beforeValidate() set the value of birthdate with combination of 3 virtual fields from the form.
  3. Add afterFind() in the model class where value of saved in DB birthdate property is used to set the values of 3 virtual properties.
  4. Now form properly holds 3 fields' values and combined date is saved in DB.
like image 118
Bizley Avatar answered Dec 11 '25 03:12

Bizley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!