是否可以在活动记录的行为方法中访问模型的当前实例?我计划的是使用当前实例的属性值来帮助配置返回值。请参阅以下示例:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors[] = [
'class' => AttributeBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'line_number',
],
'value' => function ($event) {
$maxLineNum = $this->getQuestion()->max('line_number'); // Is this possible?
return ++$maxLineNum;
},
];
return $behaviors;
}