我的Assert/Callback
验证有问题。我用它作为我的代码示例,但 Symfony 只是忽略了验证功能。这是我的实体代码的相关部分
namespace Vendor\Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo; // gedmo annotations
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
/**
* @Assert\Callback(methods={"isValidFirma"})
* @ORM\Entity(repositoryClass="Vendor\Bundle\Entity\UserProfileRepository")
* @ORM\Table(name="user_profile")
*/
class UserProfile
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
//...
public function isValidFirma(ExecutionContext $context){
$context->addViolationAtSubPath('Firma', 'Company name must be present', array(), null);
// as of sf 2.3 use addViolationAt() instead [reference: https://github.com/propelorm/PropelBundle/issues/234 ]
}
//...
}
isValidFirma
永远不会被调用。我也尝试了validation.yml 文件而不是注释,但没有成功。每次更改后,我清除了大约五十次缓存,也无济于事。可能是什么问题呢?