Hi All,

I have created callback validator with the use of below links

http://symfony.com/doc/current/reference/constraints/Callback.html

point no. 2. Static array callback

Now i want to write doctrine query in "MyStaticValidatorClass" class
file then how can i write ?

I tried with below but giving error " Fatal error: Using $this when
not in object context in C:\xampp\htdocs\avc\src\crm\paymentBundle
\MyStaticValidatorClass.php on line 15"

File Path => avc\src\crm\paymentBundle\MyStaticValidatorClass.php


My code is like below

<?php

namespace crm\paymentBundle;


use Symfony\Component\Validator\ExecutionContext;
use crm\paymentBundle\Entity\UserAccount;

class MyStaticValidatorClass
{
        static public function isAuthorValid(UserAccount $author,
ExecutionContext $context)
    {


        $emUserType = $this->getDoctrine()->getEntityManager();
        $entityUserType = $emUserType-
>getRepository('paymentBundle:userType')->findAll();

        // array of user type
                foreach($entityUserType as $key => $val){
                $arrUserType[$val->getId()] = $val->getUserType();
        }
        // somehow you have an array of "fake names"
        $fakeNames = array('ggggggggg','rrrrrrrrrr');
                // check if the name is actually a fake name
        if (in_array($author->getFirstName(), $fakeNames)) {

            $property_path = $context->getPropertyPath() .
'.firstName';
            $context->setPropertyPath($property_path);
            $context->addViolation('This name sounds totally fake!',
array(), null);
        }
    }
}




Please suggest.


Thanks in advance..

- Gaurang

-- 
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

Reply via email to