0
필드가 컬렉션 인 양식이 있으며이 컬렉션의 요소 수는 고정되어 있어야합니다. 이걸 내가 어떻게 확인할 수 있니?양식 컬렉션의 유효성을 검사하려면 X 개의 요소가 있어야합니까?
필드가 컬렉션 인 양식이 있으며이 컬렉션의 요소 수는 고정되어 있어야합니다. 이걸 내가 어떻게 확인할 수 있니?양식 컬렉션의 유효성을 검사하려면 X 개의 요소가 있어야합니까?
콜렉션을 소유 한 엔티티에 대한 사용자 정의 콜백 유효성 검사기를 작성하십시오. 당신이 장바구니 엔티티 및 예를 들어 제품의 모음이있는 경우
, 당신은 수행해야합니다
...............
use Symfony\Component\Validator\Constraints as Assert;
...............
* @Assert\Callback(
* methods={"hasCorrectNumberOfProducts"}
*)
class Cart
{
...........
public function hasCorrectNumberOfProducts(ExecutionContext $context)
{
$propertyPath = $context->getPropertyPath();
$correct = 666;
if(!count($this->getProducts()) == $correct) {
$context->setPropertyPath($propertyPath . '.products');
$context->addViolation('Incorrect number of products!', array(), null);
}
}
......