我已经实现了一个crypt
可以附加到 AR 模型的行为类,以便附加属性将作为加密存储并作为解密字符串检索。
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
)
);
}
}
这工作正常。我也有我的自定义类Myuser
,它扩展User
了模型来编写我的自定义函数,这样如果我在我的user
表中进行一些更改并重新生成模型,我就不会失去我自己的函数。
如果我将我的behavior
函数移到类MyUser
中,则行为不会附加并且无法按预期工作。
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...
}
}
任何帮助,将不胜感激。参考链接:地穴行为