gpt4 book ai didi

php - Symfony 2 与相关实体的验证

转载 作者:行者123 更新时间:2023-12-04 05:42:11 24 4
gpt4 key购买 nike

我有用户和订单实体。当用户创建订单时,我应该检查用户现金是否大于订单成本。如何做到这一点?
示例订单实体:

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

/**
* @var integer $user
*
* @ORM\ManyToOne(targetEntity="\App\UserBundle\Entity\User", inversedBy="orders")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;

/**
*
* @ORM\Column(type="integer")
* @Assert\Min(limit = "1", message = "You must enter positive number")
*/
private $price;
}

最佳答案

您需要使用 Callback .

The purpose of the Callback assertion is to let you create completely custom validation rules and to assign any validation errors to specific fields on your object.

关于php - Symfony 2 与相关实体的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11153620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com