0

我正在使用AbstractTableGatewayHydratingResultset进行数据库操作。(使用 BjyProfiler)当我使用添加操作发布表单数据时,它可以工作,但编辑操作不起作用。当我进行绑定时,它可以工作,但我重定向到添加页面,因为提交表单会重置来自路由的参数。

这是我的代码editAction()(与专辑editAction()相同)

        $id = (int)$this->params()->fromRoute('id');
        if (!$id) {
            return $this->redirect()->toRoute('voyage', array('action'=>'add'));
        }
        $voyage = $this->getVoyageTable()->getVoyage($id);

        $form = new VoyageForm($this->getTypeVoyageTable());
        $form->bind($voyage);
        $form->get('submit')->setAttribute('value', 'Edit');

        $request = $this->getRequest();
        if ($request->isPost()) {
            $form->setData($request->getPost());
            if ($form->isValid()) {
                $this->getVoyageTable()->saveVoyage($voyage);

                // Redirect to list of voyages
                return $this->redirect()->toRoute('voyage');
            }
        }

        return array(
            'id' => $id,
            'form' => $form,
        );
    }

和我的桌子:

class VoyageTable extends AbstractTableGateway
{
    protected $table ='voyages';

    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new HydratingResultSet();
        $this->resultSetPrototype->setObjectPrototype(new Voyage());
        $this->initialize();
    }
[...]

有人可以帮助我吗?我该如何解决这个问题?谢谢。

4

1 回答 1

0

由于 ClassMethods 不是默认设置,因此您需要告知表单有关 hydrator 的信息

 $form->setHydrator(new ClassMethods());
于 2013-06-02T07:27:19.487 回答