Last active
August 29, 2015 14:04
-
-
Save immutef/e144a6feb00ac9ad77ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Model; | |
use Symfony\Component\Validator\ExecutionContextInterface; | |
class MyModel | |
{ | |
public $myProperty; | |
public function validateProperty(ExecutionContextInterface $context) | |
{ | |
$context->addViolationAt('myProperty', 'Error'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Bundle\DemoBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Validator\Constraints\Callback; | |
class MyModelType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->add('myProperty', 'text'); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => 'Acme\DemoBundle\Model\MyModel', | |
'constraints' => array( | |
new Callback(array( | |
'callback' => 'validateProperty', | |
), | |
), | |
)); | |
} | |
public function getName() | |
{ | |
return 'my_model_form'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment