Encrypt/Decrypt entire model

I am wanting to encrypt/decrypt an entire model (maybe not the PK) and wondering what approach to take?

I dabbled a little and am encrypting individual columns

Yii::$app->getSecurity()->encryptByPassword();

I’m assuming I could use the model’s beforeSave, is that correct? But which event should I use to decrypt when the update/view views are used?

Any advice?

Thank you for your help!

It could be done at database level:

But it’s definitely doable your way. The event you’re looking for is afterFind.

1 Like

Thank you for the links and the proper event. Some reading ahead of me.