私はデータベース操作を行うためにAbstractTableGateway
andを使用しています。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();
}
[...]
誰か助けてくれませんか?この問題を解決するにはどうすればよいですか? ありがとう。