0
私はZend framework 3のチュートリアルを試していて、the in-depth part (Blog case)の機能を「編集」しています。zend framework 3チュートリアル
ブログメッセージを編集しようとすると、編集フォームに元のメッセージが表示されません。元のメッセージはフォームにバインドできませんでした。
すべてのサンプルコードをコピーしました。私は何が間違っているのか分からない。ちなみに、私の追加と削除の機能は正常に動作します。
誰でも私に助けてくれますか?
チュートリアルからeditAction
方法:
public function editAction()
{
$id = $this->params()->fromRoute('id');
if (! $id) {
return $this->redirect()->toRoute('blog');
}
try {
$post = $this->repository->findPost($id);
} catch (InvalidArgumentException $ex) {
return $this->redirect()->toRoute('blog');
}
$this->form->bind($post);
$viewModel = new ViewModel(['form' => $this->form]);
$request = $this->getRequest();
if (! $request->isPost()) {
return $viewModel;
}
$this->form->setData($request->getPost());
if (! $this->form->isValid()) {
return $viewModel;
}
$post = $this->command->updatePost($post);
return $this->redirect()->toRoute(
'blog/detail',
['id' => $post->getId()]
);
}
あなたのためのコードが含まれるようにあなたの質問を編集できますコントローラーの 'editAction'関数? –
こんにちはTim、あなたの返事をありがとう。 – Stwo
PostForm.phtmlの正しいinit()関数で問題を修正しました。ありがとう。 – Stwo