断言验证空数组集合 symfony
Assert validate empty array collection symfony
有没有办法验证和检查集合数组是否为空。我已经试过了:
/**
* @Assert\NotBlank()
* @Assert\Length( min = 1)
*/
protected $workPlaces;
public function __construct()
{
$this->workPlaces = new ArrayCollection();
}
试试 Count assert
// src/Entity/Participant.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Participant
{
/**
* @Assert\Count(
* min = 1,
* max = 5,
* minMessage = "You must specify at least one email",
* maxMessage = "You cannot specify more than {{ limit }} emails"
* )
*/
protected $emails = [];
}
Validates that a given collection’s (i.e. an array or an object that
implements Countable) element count is between some minimum and
maximum value.
不需要的请不要指定max
有没有办法验证和检查集合数组是否为空。我已经试过了:
/**
* @Assert\NotBlank()
* @Assert\Length( min = 1)
*/
protected $workPlaces;
public function __construct()
{
$this->workPlaces = new ArrayCollection();
}
试试 Count assert
// src/Entity/Participant.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Participant
{
/**
* @Assert\Count(
* min = 1,
* max = 5,
* minMessage = "You must specify at least one email",
* maxMessage = "You cannot specify more than {{ limit }} emails"
* )
*/
protected $emails = [];
}
Validates that a given collection’s (i.e. an array or an object that implements Countable) element count is between some minimum and maximum value.
不需要的请不要指定max