PHP如何进行类与类的关联,php – 我如何解决语义错误:“类没有名称的关联..”...

我正在遵循symblog symfony2教程的第5部分:

http://tutorial.symblog.co.uk/docs/customising-the-view-more-with-twig.html

标题下:主页 – 博客和评论

当我得到更新时:

// src/Blogger/BlogBundle/Repository/BlogRepositoy.php

public function getLatestBlogs($limit = null)

{

$qb = $this->createQueryBuilder('b')

->select('b, c')

->leftJoin('b.comments', 'c')

->addOrderBy('b.created', 'DESC');

if (false === is_null($limit))

$qb->setMaxResults($limit);

return $qb->getQuery()

->getResult();

}

当我更新时:

{# src/Blogger/BlogBundle/Resources/views/Page/index.html.twig #}

{# .. #}

Comments: {{ blog.comments|length }}

Posted by {{ blog.author }} at {{ blog.created|date('h:iA') }}

Tags: {{ blog.tags }}

{# .. #}

我然后刷新我的浏览器并得到错误:

[Semantical Error] line 0, col 71 near 'c ORDER BY b.created': Error: Class

Blogger\BlogBundle\Entity\Blog has no association named comments

500 Internal Server Error - QueryException

// 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\Repository\BlogRepository")

* @ORM\Table(name="blog")

* @ORM\HasLifecycleCallbacks()

*/

class Blog

{

public function __toString()

{

return $this->getTitle();

}

/**

* @ORM\Id

* @ORM\Column(type="integer")

* @ORM\GeneratedValue(strategy="AUTO")

*/

protected $id;

/**

* @ORM\Column(type="string")

*/

protected $title;

/**

* @ORM\Column(type="string", length=100)

*/

protected $author;

/**

* @ORM\Column(type="text")

*/

protected $blog;

/**

* @ORM\Column(type="string", length="20")

*/

protected $image;

/**

* @ORM\Column(type="text")

*/

protected $tags;

protected $comments;

/**

* @ORM\Column(type="datetime")

*/

protected $created;

/**

* @ORM\Column(type="datetime")

*/

protected $updated;

public function __construct()

{

$this->comments = new ArrayCollection();

$this->setCreated(new \DateTime());

$this->setUpdated(new \DateTime());

}

public function setUpdatedValue()

{

$this->setUpdated(new \DateTime());

}

/**

* Get id

*

* @return integer

*/

public function getId()

{

return $this->id;

}

/**

* Set title

*

* @param string $title

*/

public function setTitle($title)

{

$this->title = $title;

}

/**

* Get title

*

* @return string

*/

public function getTitle()

{

return $this->title;

}

/**

* Set author

*

* @param string $author

*/

public function setAuthor($author)

{

$this->author = $author;

}

/**

* Get author

*

* @return string

*/

public function getAuthor()

{

return $this->author;

}

/**

* Set blog

*

* @param text $blog

*/

public function setBlog($blog)

{

$this->blog = $blog;

}

/**

* Get blog

*

* @return text

*/

public function getBlog($length = null)

{

if (false === is_null($length) && $length > 0)

return substr($this->blog, 0, $length);

else

return $this->blog;

}

/**

* Set image

*

* @param string $image

*/

public function setImage($image)

{

$this->image = $image;

}

/**

* Get image

*

* @return string

*/

public function getImage()

{

return $this->image;

}

/**

* Set tags

*

* @param text $tags

*/

public function setTags($tags)

{

$this->tags = $tags;

}

/**

* Get tags

*

* @return text

*/

public function getTags()

{

return $this->tags;

}

/**

* Set created

*

* @param datetime $created

*/

public function setCreated($created)

{

$this->created = $created;

}

/**

* Get created

*

* @return datetime

*/

public function getCreated()

{

return $this->created;

}

/**

* Set updated

*

* @param datetime $updated

*/

public function setUpdated($updated)

{

$this->updated = $updated;

}

/**

* Get updated

*

* @return datetime

*/

public function getUpdated()

{

return $this->updated;

}

}

请帮忙解决这个问题.我不知道我哪里出错了

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值