2012-01-30 1 views

답변

0

콜렉션을 소유 한 엔티티에 대한 사용자 정의 콜백 유효성 검사기를 작성하십시오. 당신이 장바구니 엔티티 및 예를 들어 제품의 모음이있는 경우

, 당신은 수행해야합니다

............... 
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); 
    } 
} 
...... 
관련 문제