的ConfiguredArticle實體裏面可以有這樣的方法:
public function isLengthValid(ExecutionContextInterface $context) {
if ($this->getLength < $this->getArticleConfiguration()->getMinLength()) {
$context->addViolationAt('length', 'The length does not satisfy the minimum length', array(), null);
}
if ($this->getLength > $this->getArticleConfiguration()->getMaxLength()) {
$context->addViolationAt('length', 'The length does not satisfy the maximum length', array(), null);
}
}
public function isWidthValid(ExecutionContextInterface $context) {
if ($this->getWidth < $this->getArticleConfiguration()->getMinWidth()) {
$context->addViolationAt('width', 'The width does not satisfy the minimum width', array(), null);
}
if ($this->getWidth > $this->getArticleConfiguration()->getMaxWidth()) {
$context->addViolationAt('width', 'The width does not satisfy the maximum width', array(), null);
}
}
瞭解更多關於如何在此頁上使用回調方法進行驗證:http://symfony.com/doc/current/reference/constraints/Callback.html
是有像ConfiguredArticle的關係 - > PossibleArticleConfiguration(一到許多/一對音)? – nifr
是的,有一個關係配置文章/材料OneToMany <-> ManyToOne PossibleArticleConfiguration/Material – user1731323