我有一个接受多个id数组的表单,然后应该将它插入到数据库中。这是代码:
这是集合类型的一部分
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('records', CollectionType::class, array(
'entry_type' => EntityType::class,
'entry_options' => array(
'class' => Document::class
)
))
->add('submit', SubmitType::class);
}
这是发送AJAX POST请求的javascript的一部分:
function addDocument(runsheet, documents) {
var params = {};
params.runsheet_documents = {};
params.runsheet_documents.records = documents;
return $http.post(API_CONFIG.url + '/runsheets/' + runsheet + '/documents', params)
.success(function(current, response) {
return true;
})
.error(function(response) {
return false;
}
);
}
这是我的路线控制器:
public function postDocumentsAction(Request $request, Runsheet $runsheet)
{
$form = $this->createForm(RunsheetDocumentsType::class, $runsheet);
$form->submit($request->request->all());
$runsheet = $form->getData();
$this->get('title.api.runsheet')->update($runsheet);
$this->get('title.logger.event')->flush();
}
每当我尝试发送AJAX POST请求时,我都会得到: