Symfony - 类型的预期值改为"字符串"



我正在尝试将id从一个形成表传递到票证表,但我无法传递此错误。

关联字段"App\Entity\Ticket#$formation"的预期值类型为"App\Entity\Formation",而是获得"字符串"。

组建实体

/**
* @ORMEntity(repositoryClass="AppRepositoryFormationRepository")
*/
class Formation
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="array", nullable=true)
*/
private $formations = [];
/**
* @ORMColumn(type="string", length=180, unique=true)
*/
private $customerName;
...

票证实体

/**
* @ORMMappedSuperclass()
*/
class Ticket implements TicketInterface
{
use Timestampable;
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @ORMManyToOne(targetEntity="SymfonyComponentSecurityCoreUserUserInterface")
* @ORMJoinColumn(name="author", referencedColumnName="id", nullable=true)
*/
private $author;
/**
* @ORMManyToOne(targetEntity="AppEntityFormation")
* @ORMJoinColumn(nullable=false)
*/
private $formation;
...

我的票证控制器与addTicket()

public function addTicket(Request $request, TicketManager $ticketManager): Response
{
$ticket = $ticketManager->newClass();
$user = $this->getUser();
$formationId = $user->getFormationId()->getId();
$ticketForm = $this->createForm(TicketForm::class, $ticket);
$ticketForm->handleRequest($request);
if ($ticketForm->isSubmitted() && $ticketForm->isValid()) {
$ticketManager->createTicket($user, $ticket, $formationId);
$this->addFlash('success', 'Le ticket est en ligne !');
return $this->redirectToRoute('ticketing_list');
}
return $this->render($this->ticketingTemplates['new'], [
'form' => $ticketForm->createView(),
]);
}

还有我的票务经理与createTicket()

/**
* @param UserInterface $user
* @param TicketInterface $ticket
* @param string $formationId
* @throws DoctrineORMORMException
* @throws DoctrineORMOptimisticLockException
*/
public function createTicket(UserInterface $user, TicketInterface $ticket, string $formationId)
{
$status = $this->ticketStatusManager->getOpenStatus();
$ticket->setStatus($status)->setFormationId($formationId)->setAuthor($user)->setPublic(false);
if (!$this->isTicketRestrictionEnabled()) {
$ticket->setPublicAt(new DateTime())->setPublic(true);
}
$this->persistAndFlush($ticket);
}

我希望在添加工单时,我将"formationId"保存在工单表中。 其余的运行良好,只有 formationId 的注册

不起作用编辑:

工单实体setFormationId()的定义:

public function setFormation($formation): self
{
$this->formation = $formation;
return $this;
}

我的票证控制器与addTicket()

public function addTicket(Request $request, TicketManager $ticketManager): Response
{
$ticket = $ticketManager->newClass();
$user = $this->getUser();
$formationId = $user->getFormationId();
$ticketForm = $this->createForm(TicketForm::class, $ticket);
$ticketForm->handleRequest($request);
if ($ticketForm->isSubmitted() && $ticketForm->isValid()) {
$ticketManager->createTicket($user, $ticket, $formationId);
$this->addFlash('success', 'Le ticket est en ligne !');
return $this->redirectToRoute('ticketing_list');
}
return $this->render($this->ticketingTemplates['new'], [
'form' => $ticketForm->createView(),
]);
}

同样的错误

/**
* @param UserInterface $user
* @param TicketInterface $ticket
* @throws DoctrineORMORMException
* @throws DoctrineORMOptimisticLockException
*/
public function createTicket(UserInterface $user, TicketInterface $ticket, Formation $formation)
{
$status = $this->ticketStatusManager->getOpenStatus();
$ticket->setStatus($status)->setFormation($formation)->setAuthor($user)->setPublic(false);
if (!$this->isTicketRestrictionEnabled()) {
$ticket->setPublicAt(new DateTime())->setPublic(true);
}
$this->persistAndFlush($ticket);
}

最新更新