Je suis sur a 95%
Dans un flichier j ai ce code
$this->setValidator( 'username', new sfValidatorApplyUsername() );
Du coup je vais dans le dossier validator et j'ouvre le fichier du même nom qui ressemble à ca
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
class sfValidatorApplyUsername extends sfValidatorAnd
{
public function __construct()
{
parent::__construct();
$this->setValidators();
}
public function setValidators()
{
//Setting string validator first.
//It should be required, got trimmed, and min and max length set.
$this->addValidator(
new sfValidatorString(
array(
'required' => true,
'trim' => true,
'min_length' => 4,
'max_length' => 16
)
)
);
// Usernames should be safe to output without escaping and generally username-like.
$this->addValidator(
new sfValidatorRegex(
array( 'pattern' => '/^\w+$/ ' ),
array( 'invalid' => 'Le pseudo doit contenir uniquement des lettres, chiffres ou underscores.')
)
);
//Checking for existance of given username in database
$this->addValidator(
new sfValidatorDoctrineUnique(
array( 'model' => 'sfGuardUser', 'column' => 'username' ),
array('invalid' => 'Le pseudo est déjà pris. Choisissez en un autre')
)
);
}
} |
Partager