duanbo7517 2016-08-13 14:57
浏览 60

zend框架3教程

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()]
    );
}
  • 写回答

1条回答 默认 最新

  • doubei8168 2017-02-10 02:58
    关注

    Edit this code:

    if (! $request->isPost()) {
        foreach($this->form->getMessages() as $message){
            $this->flashMessenger()->addErrorMessage($message['message']);
        }
    }
    

    In your view:

    <?php echo $this->flashMessenger()->renderCurrent('error', ['options go here...']); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM