在我的mysql数据库中,有一个articleID作为AI PK和一个articleNumber,用户可以编辑它。
问题:
在yii2 ActiveForm中,我想让用户输入articleNumber,同时在后台保存articleID。
到目前为止,我创建了几个具有关系的模型。
我已经在我的GridView:中工作了
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'article.details.articleNumber',
'label' => 'ArtNr.',
],
]
]);
在我的创建/编辑表单中,这对我不起作用:
<?= $form->field($model, 'article.details.articleNumber')->textInput() ?>
我刚开始创建yii2应用程序,在文档中找不到任何内容。我是用了错误的方式来归档我的目标,还是有技巧来管理它?
您需要在这里使用多个模型表单。即,在表单中,您需要传递两个模型,一个用于articleNumber,另一个用于关系表的模型用于文章详细信息。
例如,您可以参考以下链接:http://blog.dedikisme.com/blog/2014/10/13/yii2-building-a-single-form-with-multiple-models