Skip to content

Instantly share code, notes, and snippets.

/gist:e09725bef42715ed813f Secret
Created May 17, 2013

Embed
What would you like to do?
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class Pages
{
public $title;
public $lead;
}
class PagesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('lead')
;
$builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) {
echo "[Form] Post set data event\n";
});
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
echo "[Form] Pre set data event\n";
});
$builder->addEventListener(FormEvents::PRE_BIND, function(FormEvent $event) {
echo "[Form] Pre bind event\n";
});
$builder->addEventListener(FormEvents::POST_BIND, function(FormEvent $event) {
echo "[Form] Post bind event\n";
});
$builder->addEventListener(FormEvents::BIND, function(FormEvent $event) {
echo "[Form] Bind event\n";
});
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\DemoBundle\Controller\Pages',
);
}
public function getName()
{
return 'form_name';
}
}
class WelcomeController extends Controller
{
public function indexAction()
{
$p = new Pages();
$p->title = 'Tytul';
$p->lead = 'Lead!';
echo '<pre>';
echo "[Controller] Create Form\n";
$form = $this->createForm(new PagesType(), $p, array());
echo "[Controller] Bind form\n";
$form->bind(array(
'title' => 'Nowy tytul',
'lead' => 'Lead2!'
));
echo '</pre>';
return $this->render('AcmeDemoBundle:Welcome:index.html.twig');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.