找不到目标实体

时间:2016-01-02 06:47:39

标签: entity-framework symfony

我知道这个问题已被不止一次提出过,但我仍然无法弄清楚会出现什么问题。

我目前正在尝试学习Symfony2(使用版本2.7.4),当我试图访问一个应该包含图像的页面时,我收到以下错误:

  

在'OC \ PlatformBundle \ Entity \ Advert#Image'中找不到目标实体Entity \ Image。

这是我的代码:

**advert.php**

<?php

namespace OC\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="OC\PlatformBundle\Entity\AdvertRepository")
 */
class Advert
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
* @ORM\Column(name="published", type="boolean")
*/
private $published = true;

/**
* @ORM\OneToOne(targetEntity="Entity\Image", cascade={"persist"})
*/
  private $image;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="date", type="datetime")
 */
private $date;

/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 */
private $title;

/**
 * @var string
 *
 * @ORM\Column(name="author", type="string", length=255)
 */
private $author;

/**
 * @var string
 *
 * @ORM\Column(name="content", type="text")
 */
private $content;

/**
 * Set image
 *
 * @param \OC\PlatformBundle\Entity\Image $image
 *
 * @return Advert
 */
public function setImage(\OC\PlatformBundle\Entity\Image $image = null)
{
    $this->image = $image;

    return $this;
}

/**
 * Get Image
 *
 * @return \OC\PlatformBundle\Entity\Image
 */
public function getImage()
{
    return $this->Image;
}


/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

public function __construct()
{
    // Par défaut, la date de l'annonce est la date d'aujourd'hui
    $this->date = new \Datetime();
}

/**
 * Set date
 *
 * @param \DateTime $date
 *
 * @return Advert
 */
public function setDate($date)
{
    $this->date = $date;

    return $this;
}

/**
 * Get date
 *
 * @return \DateTime
 */
public function getDate()
{
    return $this->date;
}

/**
 * Set title
 *
 * @param string $title
 *
 * @return Advert
 */
public function setTitle($title)
{
    $this->title = $title;

    return $this;
}

/**
 * Get title
 *
 * @return string
 */
public function getTitle()
{
    return $this->title;
}

/**
 * Set author
 *
 * @param string $author
 *
 * @return Advert
 */
public function setAuthor($author)
{
    $this->author = $author;

    return $this;
}

/**
 * Get author
 *
 * @return string
 */
public function getAuthor()
{
    return $this->author;
}

/**
 * Set content
 *
 * @param string $content
 *
 * @return Advert
 */
public function setContent($content)
{
    $this->content = $content;

    return $this;
}

/**
 * Get content
 *
 * @return string
 */
public function getContent()
{
    return $this->content;
}

/**
 * Set published
 *
 * @param boolean $published
 *
 * @return Advert
 */
public function setPublished($published)
{
    $this->published = $published;

    return $this;
}

/**
 * Get published
 *
 * @return boolean
 */
public function getPublished()
{
    return $this->published;
}
}

文件图片

<?php
// src/OC/PlatformBundle/Entity/Image

namespace OC\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Image
{
  /**
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;

  /**
   * @ORM\Column(name="url", type="string", length=255)
   */
  private $url;

  /**
   * @ORM\Column(name="alt", type="string", length=255)
   */
  private $alt;
}

我明白这个问题主要来自实体调用中的错字,但我对所有内容进行了三重检查,对我来说似乎没问题......是否有一些我没看到的内容?

提前谢谢

1 个答案:

答案 0 :(得分:1)

您应该修复注释:

/**
 * @ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist"})
 */
private $image;