Domanda

I want to define email validator with annotation, like this

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Validator\Constraints as Assert;

/** 
 * @ODM\Document(collection="dummies")
 */
class Dummy
{
    /** @ODM\Id */
    private $id;

    /** @ODM\String @Assert\Email() */
    private $email;
}
È stato utile?

Soluzione

Doctrine explains reasons for not including validators here

Symfony has a nice form validator built in.

You could also construct a callback

/**
* @Entity
* @HasLifecycleCallbacks
*/
/**
 * @PrePersist @PreUpdate
 */
public function validateEmail() {
//validation
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top