Yii中模型/ActiveRecord的“加载后”事件

Yii中模型/ActiveRecord的“加载后”事件,yii,Yii,当从DB加载记录,并且模型对象(通常是CActiveRecord子代)中填充了适当的数据时,我找不到截获事件的方法—这对于onAfterSave来说是简单的。列出了以下事件:onAfterConstruct、onAfterDelete、onAfterFind、onAfterSave、, onAfterValidate、onBeforeDelete、onBeforeFind、onBeforeSave、onBeforeValidate、OnUnsFeatureAttribute 唯一可能相关的是On

当从DB加载记录,并且模型对象(通常是CActiveRecord子代)中填充了适当的数据时,我找不到截获事件的方法—这对于onAfterSave来说是简单的。列出了以下事件:onAfterConstruct、onAfterDelete、onAfterFind、onAfterSave、, onAfterValidate、onBeforeDelete、onBeforeFind、onBeforeSave、onBeforeValidate、OnUnsFeatureAttribute

唯一可能相关的是OnAfterConstruction,因此我在从CActiveRecord派生的模型类中实现了事件处理程序,但它没有被调用

更新:


除了公认的答案外,我还发现有一种受保护的方法,其目的非常相同。可以重写它以访问新实例的属性。最重要的是,它是在记录的任何实例化之后调用的,而不仅仅是在查找之后调用的,因此它似乎更可靠。

我认为您要查找的是onAfterFind,onAfterFind是在记录实例化之后提出的,vs onAfterConstruct是在新操作符创建模型实例后引发的,我想你要找的是onAfterFind,onAfterFind是在记录实例化后引发的,vs onAfterConstruct是在CActiveRecord.php中的新操作符创建模型实例后引发的,你也有 函数populateRecord$attributes,$callAfterFind=true 这是一个:

//instantiate: by default only returns a new empty object of this class
$record = instantiate() 

//then fill all the record attributes
...

//call afterfind
if($callAfterFind) $record->afterFind();
这意味着每次加载记录时,都会调用afterFind。
我没有找到其他填充记录值的地方,因此似乎afterFind可以解释为after load/afterLoad google请在CActiveRecord.php中将其索引 函数populateRecord$attributes,$callAfterFind=true 这是一个:

//instantiate: by default only returns a new empty object of this class
$record = instantiate() 

//then fill all the record attributes
...

//call afterfind
if($callAfterFind) $record->afterFind();
这意味着每次加载记录时,都会调用afterFind。
我没有找到其他地方可以填充记录值,因此似乎afterFind可以解释为after load/afterLoad google请将此索引

谢谢,它可以工作。我发现了另一个方法-实例化,所以我将更新我的问题。谢谢,它可以工作。我发现了另一个方法-实例化,所以我将更新我的问题。谷歌已经听到你了谷歌已经听到你了