在渲染模板期间抛出异常(" A" __ toString()"

时间:2014-05-30 11:36:13

标签: php symfony

我在继续这个过程中遇到了这个错误 tutorial.symblog.co.uk [第4部分] -评论模型:添加评论,学说知识库和迁移]

  

在渲染模板期间抛出异常(" A" __ toString()"在#34; Blogger \ BlogBu​​ndle \ Entity \类型的对象上找不到方法Blog"传递到选择字段。要读取自定义getter,请将选项" property"设置为所需的属性路径。")   在BloggerBlogBu​​ndle:Blog:show.html.twig第23行。

有人知道这个吗?

// src/Blogger/BlogBundle/Entity/Blog.php 
namespace Blogger\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/** 
 * @ORM\Entity(repositoryClass="Blogger\BlogBundle\Entity\Repository\BlogRepository‌​") 
 * @ORM\Table(name="blog") 
 * @ORM\HasLifecycleCallbacks() 
 */ 
class Blog { 
    //.......... 
    public function __toString() { 
        return $this->getTitle(); 
    } 
}

1 个答案:

答案 0 :(得分:3)

只需在__toString()实体

中添加Blog方法即可
class Blog {

    //...

    function __toString() {
        return $this->getTitle(); // or any other field
    }
}
相关问题