dragon87836215 2015-07-17 09:33
浏览 34
已采纳

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

1条回答 默认 最新

  • douluozhan4370 2015-07-20 16:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了