I have implemented a crypt
behavior class that can be attached to a AR model so that, attached attributes will be stored as encrypted and retrieved as decrypted string.
class User extends CActiveRecord
{
public function behaviors()
{
return array(
'crypt' => array(
// this assumes that the behavior is in the folder: protected/behaviors/
'class' => 'application.behaviors.CryptBehavior',
// this sets that the attributes to be encrypted/decrypted are encryptedfieldname of the model
'attributes' => array('password'),
'useAESMySql' => true
)
);
}
}
This is working fine. I am also having my custom class Myuser
which extends User
model to write my custom functions so that if i make some change in my user
table and regenerate model, i wont loose my own functions.
If i move my behavior
function to the class MyUser
, the behavior is not getting attached and not working as expected.
class MyUser extends User
{
public function behaviors()
{
return array(
'crypt' => array(
// this assumes that the behavior is in the folder: protected/behaviors/
'class' => 'application.behaviors.CryptBehavior',
// this sets that the attributes to be encrypted/decrypted are encryptedfieldname of the model
'attributes' => array('password'),
'useAESMySql' => true
)
);
}
public function customfn1()
{
//some code goes here...
}
}
Any help would be appreciated. Reference Link: Crypt Behavior