无法在同一名称空间中找到目标实体

时间:2017-09-23 20:00:23

标签: php symfony entity

大家好,我有一个奇怪的错误。

我有两个实体,它们位于相同的命名空间中,但它们不在同一个文件夹中:
- 卡实体位于AppBundle \ Entity \ Card文件夹中 - Minnie实体位于AppBundle \ Entity \ Card \ Subfolder文件夹中 当我使用卡实体时,它说:

  

在'AppBundle \ Entity \ Card \ Card#minnies'中找不到目标实体AppBundle \ Entity \ Card \ Minnie。

我无法理解为什么。我在这个论坛上搜索过,每个人都说如果两个类在同一个命名空间中,那么当我使用一个推荐者到Minnie的实体时,它只需要实体的名字。为什么在这种情况下它不起作用?

卡类:

namespace AppBundle\Entity\Card;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="card")
 */
class Card {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

/**
 * @ORM\Column(length=55)
 */
private $name;

/**
 * Many Cards have Many Pippos.
 * @ORM\ManyToMany(targetEntity="Pippo", inversedBy="cards")
 * @ORM\JoinTable(name="pippo_jointable")
 */
private $pippos;

/**
 * Many Cards have Many Topolinos.
 * @ORM\ManyToMany(targetEntity="Topolino", inversedBy="cards")
 * @ORM\JoinTable(name="topolino_jointable")
 */
private $topolinos;

/**
 * Many Cards have Many Minnie.
 * @ORM\ManyToMany(targetEntity="Minnie", inversedBy="cards")
 * @ORM\JoinTable(name="minnie_jointable")
 */
private $minnies;

public function __construct() {
    $this->pippos= new ArrayCollection();
    $this->topolinos = new ArrayCollection();
    $this->minnies = new ArrayCollection();
}
}

米妮的班级:

namespace AppBundle\Entity\Card;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="minnie")
 */
class Minnie {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

/**
 * @ORM\Column(length=55)
 */
private $name;

/**
 * Many Minnie have Many Cards.
 * @ORM\ManyToMany(targetEntity="Card", mappedBy="minnies")
 */
private $cards;

public function __construct() {
    $this->cards = new ArrayCollection();
}
}

如果可以提供帮助,这是使用Card实体的代码:

namespace AppBundle\Controller\Admin;

use AppBundle\Entity\Card\Card;
use AppBundle\Form\CardType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class CardController extends Controller
{
    /**
     * @Route("/admin/create-card", name="create-card")
     */
    public function adminCardMainPageAction(Request $request) {
        $card = new Card();
        $em = $this->getDoctrine()->getManager();
        $form = $this->createForm(CardType::class, $card);
        $form->handleRequest($request);
        return $this->render('/admin/card-creation.html.twig', array(
            'form' => $form->createView()
        ));
    }
}

0 个答案:

没有答案