dropbox1111
2018-04-25 16:42
浏览 88
已采纳

Symfony 3.4表单中的CollectionType数组

I've got the array Cart of the entities, and I want to generate general form, which looks like on the screen.

enter image description here

As you see, I want to have editable field Quantity in each row, which represents the Cart entity, and I want to have ability to update all of them at once.

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

/**
 * @ORM\ManyToOne(targetEntity="User", inversedBy="carts")
 */
private $userId;

/**
 * @ORM\ManyToOne(targetEntity="Product", inversedBy="carts")
 */
protected $product;

/**
 * @ORM\Column(type="integer")
 */
private $quantity;

/*gettes & setters */
}

For now, I have form, which wants to receive CollectionType, to work on it, but - I have only an array of entities, so It's dumping LogicalException.

What I need to do - there is any way to parse array to CollectionType, or maybe I could take group of cart entities from database in another way than that?:

$carts=$this->getDoctrine()->getRepository(Cart::class)->findByUserId($user);

图片转代码服务由CSDN问答提供 功能建议

我有实体的数组Cart,我想生成一般形式,看起来像是 屏幕。

如您所见,我希望每行都有可编辑的字段数量 ,表示Cart实体,我希望能够立即更新所有这些。

  class Cart 
 {
 / ** 
 * @ORM  \ id 
 * @ORM \ Column(type =“integer”)
 * @ORM \ GeneratedValue(strategy =“AUTO”)
 * / 
 nrivate $ id; 
 
 / ** 
 * @  ORM \ ManyToOne(targetEntity =“User”,inversedBy =“carts”)
 * / 
private $ userId; 
 
 / ** 
 * @ORM \ ManyToOne(targetEntity =“Product”,inversedBy =“carts  “)
 * / 
保护$ product; 
 
 / ** 
 * @ORM \ Column(type =”integer“)
 * / 
 nrivate $ quantity; 
 
 / * gettes&  setters * / 
} 
   
 
 

现在,我有一个想要接收CollectionType的表单来处理它,但是 - 我只有一个实体数组 ,所以它正在转储LogicalException。

我需要做什么 - 有什么方法可以将数组解析为CollectionType,或者我可以用另一种方式从数据库中取出一组购物车实体? :

 <代码> $推车= $这 - &GT; getDoctrine() - &GT; getRepository(车::类) - &GT; findByUserId($用户); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题