Symfony 2:非映射字段

时间:2015-05-20 16:03:55

标签: php forms symfony

我的Symfony2表单有一个底层数据结构,但在我的表单中,我有一些额外的字段被声明为非映射。我在将数据添加到表单时为其分配数据:

$form->add('cell_0_1', 'textarea', array(
    'data'     => $connection->outputCellData($col, $recordsDoc, $records->item($rowNo), true), 
    'mapped'   => false,
    'required' => false
));

然后我显示这些字段,将createView()的结果传递给我的表单:

return $this->render(
    'ModesBundle:Modes:editgrid.html.twig',
    array(
        'toolbar'    => $toolbarForm->createView(),
        'records'    => $recs,
        'connection' => $connection,
        'navigator'  => $connection->navigator,
    )
);

非映射字段可以显示在我的表单上,但是我分配给它们的数据已经丢失。我的树枝模板包含例如:

<td>{{ form_widget(toolbar.cell_0_1) }}</td>

这是预期的行为吗?我的处理程序如下:

public function browserAction(Request $request, $action) {
    $connection = $this->getModesConnection();
    $toolbarForm = $this->getToolbarForm($request, $connection);
    $this->prepareEdit($toolbarForm, 'update-termlist', $connection);
    $this->updateFormWithConnectionSettings($connection, $toolbarForm, 'update-termlist');
    $this->updateFormWithGrid($toolbarForm, $connection);
    $toolbarForm->handleRequest($request);
    switch ($connection->getAction()) {
      ...
        case 'edit':
            switch ($connection->getView()) {
                ...
                case 'grid':
                    $recs = $connection->getEditGrid($toolbarForm);
                    return $this->render('ModesBundle:Modes:editgrid.html.twig',
                        array('toolbar' => $toolbarForm->createView(), 'records'=> $recs, 'connection' => $connection, 'navigator' => $connection->navigator, ));
                    break;

$ toolbarForm包含我所有的非映射网格单元格字段,但它们的数据值在命令期间的某个时刻设置为null(modelData,normData)或空字符串(viewData):

    $toolbarForm->handleRequest($request);

0 个答案:

没有答案