0
我一直在挣扎学说,我已经得到了博客文章的实体,它引用的意见和它抛出以下错误: 注意:未定义指数:POST_ID学说2协会投掷警告
这也得到所有的评论,无论post_id。这里是我的映射:
/**
* @OneToMany(targetEntity="CommentsBundle\Entities\Comments", mappedBy="post_id")
*/
protected $comments;
编辑
这里的评论实体:
<?php
namespace CommentsBundle\Entities;
use Doctrine\ORM\Mapping AS ORM;
/**
* @Entity @Table(name="comments")
**/
class Comments
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column(type="string") */
protected $name;
/** @Column(type="string") */
protected $email;
/** @Column(type="string") */
protected $content;
/** @Column(type="string") */
protected $date;
/** @Column(type="integer") */
protected $user_id;
/** @Column(type="integer") */
protected $post_id;
/**
* @ORM\ManyToOne(targetEntity="ContentBundle\Entities\Posts", inversedBy="comments")
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
*/
protected $post;
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setContent($content)
{
$this->content = $content;
return $this;
}
public function getContent()
{
return $this->content;
}
public function setDate($date)
{
$this->date = $date;
return $this;
}
public function getDate()
{
return $this->date;
}
public function setUser_id($user_id)
{
$this->user_id = $user_id;
}
public function getUser_id()
{
return $this->user_id;
}
public function setPost_id($post_id)
{
$this->post_id = $post_id;
return $this;
}
public function getPost_id()
{
return $this->post_id;
}
}
提前感谢!
是不是在Symfony2(你似乎使用)中的实体目录称为“实体”而不是“实体”? – Jivan
我实际上使用Silex,我的大部分代码都是这样保存的 src/BundleName/Controllers src/BundleName/Entities src/BundleName/Views –
ok。你关系的另一面是什么?你可以编辑你的帖子来显示这个? – Jivan