Symfony 类型为“?App\Entity\ProductPriceOptions”的预期参数,“字符串”给定

问题描述 投票:0回答:0

我的问题如下所示。

我尝试创建一个表单,您可以在其中选择您需要的产品的包装,然后将其上传到购物车,但是这个代码有问题

控制器:

`$add_cart_item = new ShoppingCart();
        $add_cart_item_form = $this->createFormBuilder($add_cart_item)
            ->add('ProductPriceOption', ChoiceType::class, [
                'choices' => $show_price_options])

            ->add('ProductTransportOption', ChoiceType::class, [
                'choices' => $show_delivery_options])

            ->add('Order', SubmitType::class, [
                'label' => 'Add cart_'])
            ->getForm();


        $add_cart_item_form->handleRequest($request);
        if($add_cart_item_form->isSubmitted() && $add_cart_item_form->isValid()){
            $entityManager->persist($add_cart_item);

            $add_cart_item->setUser($user->getId());
            $add_cart_item->setProduct($prod_id);

            $entityManager->flush();
        }`

购物车实体:

`namespace App\Entity;

use App\Repository\ShoppingCartRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ShoppingCartRepository::class)]
class ShoppingCart
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private $id;

    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'shoppingCarts')]
    private $user;

    #[ORM\Column(type: 'smallint')]
    private $Productpiece;

    #[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'shoppingCarts')]
    private $Product;

    #[ORM\ManyToOne(targetEntity: ProductPriceOptions::class, inversedBy: 'shoppingCarts')]
    private $ProductPriceOption;

    #[ORM\ManyToOne(targetEntity: ProductTransportOptions::class, inversedBy: 'shoppingCarts')]
    private $ProductTransportOption;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getProductpiece(): ?int
    {
        return $this->productpiece;
    }

    public function setProductpiece(int $productpiece): self
    {
        $this->productpiece = $productpiece;

        return $this;
    }

    public function getProduct(): ?Product
    {
        return $this->Product;
    }

    public function setProduct(?Product $Product): self
    {
        $this->Product = $Product;

        return $this;
    }

    public function getProductPriceOption(): ?ProductPriceOptions
    {
        return $this->ProductPriceOption;
    }

    public function setProductPriceOption(?ProductPriceOptions $ProductPriceOption): self
    {
        $this->ProductPriceOption = $ProductPriceOption;

        return $this;
    }

    public function getProductTransportOption(): ?ProductTransportOptions
    {
        return $this->ProductTransportOption;
    }

    public function setProductTransportOption(?ProductTransportOptions $ProductTransportOption): self
    {
        $this->ProductTransportOption = $ProductTransportOption;

        return $this;
    }
}`

问题可能是由于数据传输引起的。 现在生成的表单包含一个可打开数组的数据,并且可以从中选择包。但是由于某种原因,格式不符合要求。

php symfony doctrine
© www.soinside.com 2019 - 2024. All rights reserved.