Yii Framework Forum: Yii2: Encode/decode Activerecord Attributes Before/after Save ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   mcd.php 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 30-July 13

Posted 19 September 2013 - 07:48 AM

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

Question:
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.
0

#2 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,257
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 20 September 2013 - 07:45 AM

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! :]
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users