到现在为止一切都很完美。我在页面上:http://framework.zend.com/manual/current/en/in-depth-guide/understanding-routing.html。
在这个页面上,我必须修改3个文件:
-module.config.php
-detail.phtml
-ListController.php
我得到以下错误:
张贴细节 职位名称 致命错误:在第6行的C:\ProgramFiles\xampp\htdocs\path\to\zf2-tutorial\module\Blog\view\blog\list\detail.phtml中调用null上的成员函数getTitle()
我没有粘贴代码,因为链接中的代码是相同的。你们能帮我解决我的问题吗?
公共职能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
));
}发布于 2015-07-20 16:24:06
感谢你的更新。现在我已经了解了您在教程中的位置,我认为您在Mapper中有一个问题。见上一页和章节Finishing the Mapper
如果映射程序找不到一篇文章,它应该抛出一个错误,如第63行的代码示例所示。显然,映射器返回null,这将导致所看到的Call to a member function getTitle() on null错误。因为null毕竟不是一个对象,并且没有getTitle()函数。
因此,看看ZendDbSqlMapper类和find($id)方法,并确保如果找不到id,它就会抛出一个错误。
https://stackoverflow.com/questions/31472651
复制相似问题