我正在尝试Zend framework 3教程,却被the in-depth part (Blog case)中的函数“编辑”所困住了。
尝试编辑博客消息时,编辑表单不显示原始消息。原始消息似乎无法绑定到表单。
我复制了所有的示例代码。我不知道它有什么问题。顺便说一下,我的添加和删除功能运行良好。
有人能帮我吗?
本教程中的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()]
);
}发布于 2017-02-10 10:58:49
编辑此代码:
if (! $request->isPost()) {
foreach($this->form->getMessages() as $message){
$this->flashMessenger()->addErrorMessage($message['message']);
}
}在您的视图中:
<?php echo $this->flashMessenger()->renderCurrent('error', ['options go here...']); ?>https://stackoverflow.com/questions/38933965
复制相似问题