ZendFramework 2教程帖子标题:getTitle()致命错误

Everything until now worked perfectly. I'm on page: http://framework.zend.com/manual/current/en/in-depth-guide/understanding-routing.html.

On this page I had to modify 3 files:

-module.config.php

-detail.phtml

-ListController.php

I get the following error:

Post Details

Post Title

Fatal error: Call to a member function getTitle() on null in C:\Program Files\xampp\htdocs\path\to\zf2-tutorial\module\Blog\view\blog\list\detail.phtml on line 6

I didn't paste the code, because it's the same from the link. Can you guys help me figure out my problem?

public function detailAction()

{
    $id = $this->params()->fromRoute('id');

    try {
        $post = $this->postService->findPost($id);
    } catch (\InvalidArgumentException $ex) {
        return $this->redirect()->toRoute('blog');
    }

    return new ViewModel(array(
        'post' => $post
    ));
}

Thanks for the update. Now that I see where you are in the tutorial I think you have a problem in the Mapper. See the previous page and chapter Finishing the Mapper

If your mapper cannot find an article it should throw an error as seen in that code example on line 63. Obviously your mapper returns null which causes the error you see Call to a member function getTitle() on null. Because null is not an object after all and doesn't have a getTitle() function.

So have a look at the ZendDbSqlMapper class and the find($id) method and make sure it throws an error if an id isn't found.