Yii2: Encode/decode Activerecord Attributes Before/after Save ?

To moderators: Please move topic and give me rights for Yii 2.0 section.


How can i have encode/decode some fields of ActiveRecord before/after database ?

My database (Apache Cassandra) has annoying auto-typing, i.e. it rejects integers in columns defined as text. I want to protect this values by adding guard symbol and have it automatically removed.

You’re developing in Yii2, even though it hasn’t even reached ALPHA stage? Wow! Congrats! :]

In Yii you can use beforeSave and afterSave events and you have full access to model at that moment, so you can do whatever you want with any field (attribute) you want. Actually beforeSave in models is often used to "secure" anything that could break database or do some other nifty things, developer would like to avoid.

It is quite hard for me to believe, that Yii2 is that far different, that the same wouldn’t be possible there. But… who knows, things happens! :]