Does not work
File: AG\WebdemoBundle\Validator\PasswordAG.php
<?php
namespace AG\WebdemoBundle\Validator;
use Symfony\Component\Validator\Constraint;
class PasswordAG extends Constraint
{
public $message = 'Passwords don`t match';
}
?>
File: AG\WebdemoBundle\Validator\PasswordAGValidator.php
<?php
namespace AG\WebdemoBundle\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class PasswordAGValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
if ($value) {
$this->setMessage($constraint->message);
return false;
}
return false;
}
}
?>
File: AG\WebdemoBundle\Resources\validation.yml
# Edudata/PortalBundle/Resources/config/validation.yml
AG\WebdemoBundle\Entity\Usuario:
properties:
usuaRut:
- NotBlank: {message: "Debe ingresar un valor"}
- Min: {limit: 9, message: "Debe ser un valor de mínimo 9
caracteres"}
usuaPassword:
- NotBlank: {message: "Debe ingresar un valor"}
- Min: {limit: 9, message: "Debe ser un valor de mínimo 8
caracteres"}
- PasswordAG: {message: "Probando"}
File: AG\WebdemoBundle\Entity\Usuario
<?php
namespace AG\WebdemoBundle\Entity;
use AG\WebdemoBundle\Validator\PasswordAG;
/**
* AG\WebdemoBundle\Entity\Usuario
*/
class Usuario
{
/**
* @var integer $usuaId
*/
private $usuaId;
/**
* @var integer $usuaRut
*/
private $usuaRut;
/**
* @var string $usuaDv
*/
private $usuaDv;
/**
* @var string $usuaNombre
*/
private $usuaNombre;
/**
* @var string $usuaPassword
*/
private $usuaPassword;
Thanks
AG
On 2 jun, 09:04, Christophe COEVOET <[email protected]> wrote:
> Le 02/06/2011 14:15, cosmin a crit :
>
>
>
>
>
>
>
> > I tried to build my own custom validation and created @Assert/Password
>
> > i could not manage to figure out how to add the validator in
> > config.yml and because of this the first time i got this error
> > AnnotationException: [Semantical Error] The annotation "@Symfony
> > \Component\Validator\Constraints\Password" in property MYNSP\MyBundle
> > \Entity\User::$password does not exist, or could not be auto-loaded.
>
> > and after an refresh the error disapears and $form->isValid() returns
> > allways true even if it should return false
>
> > CODE::
>
> > namespace Symfony\Component\Validator\Constraints;
>
> > class Password extends \Symfony\Component\Validator\Constraint
> > {
> > public $message = 'Passwords don`t match';
> > }
>
> > namespace Symfony\Component\Validator\Constraints;
>
> > use Symfony\Component\Validator\Constraint;
> > use Symfony\Component\Validator\ConstraintValidator;
>
> > class PasswordValidator extends ConstraintValidator
> > {
> > public function isValid($value, Constraint $constraint)
> > {
> > if (!condition) {
> > $this->setMessage($constraint->message);
>
> > return false;
> > }
>
> > return false;
> > }
> > }
>
> If you create your own constraint, it should not be placed in the
> Symfony\Component\Validator\Constraint namespace as this would require
> putting the file in the Symfony code. (same is true for all classes you
> create)
>
> --
> Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en