I am trying a Zend framework 3 tutorial and am getting stuck in "editing" a function in the in-depth part (Blog case).
When trying to edit a blog message, the editing form doesn't show the original message. It seems that the original message couldn't be bound to the form.
I copied all the sample code. I don't know what is wrong with it. By the way, my add and delete function work fine.
can anyone help me with it?
The editAction
method from the tutorial:
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()]
);
}
Edit this code:
In your view: