关于php:在渲染模板的过程中抛出了异常(“A”__toString()”

An exception has been thrown during the rendering of a template ("A "__toString()"

我在继续操作时遇到了这个错误
tutorial.symblog.co.uk[第 4 部分]-评论模型:添加评论、Doctrine 存储库和迁移]

An exception has been thrown during the rendering of a template ("A"__toString()" method was not found on the objects of type"Blogger\BlogBundle\Entity\Blog" passed to the choice field. To read a custom getter instead, set the option"property" to the desired property path.")
in BloggerBlogBundle:Blog:show.html.twig at line 23.

有人对此有所了解吗?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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
epository\BlogRepositorya€?a€?")
 * @ORM\Table(name="blog")
 * @ORM\HasLifecycleCallbacks()
 */

class Blog {
    //..........
    public function __toString() {
        return $this->getTitle();
    }
}

相关讨论

  • 您能否添加给出错误的代码?
  • tutorial.symblog.co.uk/docs/… // src/Blogger/BlogBu??ndle/Entity/Blog.php 命名空间 Blogger\\\\BlogBu??ndle\\\\Entity;使用 Doctrine\\\\ORM\\\\Mapping 作为 ORM;使用 Doctrine\\\\Common\\\\Collections\\\\ArrayCollection; /** * @ORM\\\\Entity(repositoryClass="Blogger\\\\BlogBu??ndle\\\\Entity\\
    epos??itory\\\\BlogRepository??") * @ORM\\\\Table(name="blog") * @ORM\\\\HasLifecycleCallbacks() */ class Blog { //.. ........ 公共函数 __toString() { return $this->getTitle(); } }
  • 这是我从这里 tutorial.symblog.co.uk/docs/... 找到的,我正在关注"视图"部分 thnx..
  • @bartek 在下面为您提供了答案。那应该可以解决您的问题。

只需在 Blog 实体中添加 __toString() 方法

1
2
3
4
5
6
7
8
class Blog {

    //...

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


以上是关于php:在渲染模板的过程中抛出了异常(“A”__toString()”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>