关于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
    }
}


来源:https://www.codenong.com/23953672/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9775.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?