【发布时间】:2018-11-29 13:13:29
【问题描述】:
我创建了一个与另一个模型有关系的模型。我使用关系管理器小部件来处理关系。一切都很好。
现在,我需要根据父模型中字段的选择动态地将字段添加到关系模型中。我注意到有针对那个的 relationExtendManageWidget() 函数。
但是,我不知道如何使用它,文档也没有提供任何示例。我试图这样做:
public function relationExtendManageWidget($widget, $field, $model)
{
// Make sure the field is the expected one
if ($field != 'references') return;
$widget->addFields([
'test' => [
'label' => 'Test',
'span' => 'left',
'type' => 'text',
],
]);
return $widget;
}
但是当我转到我的表单时,我收到以下错误:
在 null 上调用成员函数 addField() /modules/backend/widgets/Form.php 第 569 行
【问题讨论】:
-
只是有人想知道,
relationExtendManageWidget方法在\Backend\Behaviors\RelationController中定义,并且应该在您的控制器中被覆盖以使用它。 -
relationExtendManageWidget预计不会返回任何内容。它会被忽略。
标签: field backend octobercms