【发布时间】:2012-10-26 09:13:27
【问题描述】:
我已经实现了一个 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...
}
}
任何帮助将不胜感激。 参考链接:Crypt Behavior
【问题讨论】:
-
我在任何地方都找不到 cryptbehavior 扩展,这是您自己的行为吗?可以粘贴行为的粗略轮廓,它扩展了哪个类,以及它实现/具有哪些功能就足够了。
-
用参考链接更新了帖子!。感谢您的关注。
-
没问题,让我看看能不能帮忙
-
我认为这个博客给了我一些路线图来实现我想要的。 invisipunk.blogspot.in/2011/01/…
-
你的 yii 是哪个版本的?
标签: activerecord yii behavior