0

私はデータベース操作を行うためにAbstractTableGatewayandを使用しています。HydratingResultset(BjyProfiler を使用) add アクションを使用してフォーム データを投稿すると機能しますが、編集アクションは機能しません。バインドを作成すると機能しますが、フォームを送信するとルートからのパラメーターがリセットされるため、追加ページにリダイレクトされます。

これが私のコードですeditAction()(Album 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 はデフォルトではないため、ハイドレーターについてフォームに通知する必要があります。

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