2016-08-13 8 views
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()] 
    ); 
} 
+0

あなたのためのコードが含まれるようにあなたの質問を編集できますコントローラーの 'editAction'関数? –

+0

こんにちはTim、あなたの返事をありがとう。 – Stwo

+0

PostForm.phtmlの正しいinit()関数で問題を修正しました。ありがとう。 – Stwo

答えて

0

編集このコード:あなたのビューで

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

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