Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2014 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e2562cc03bc4b284acf6 to your computer and use it in GitHub Desktop.
Save anonymous/e2562cc03bc4b284acf6 to your computer and use it in GitHub Desktop.
Book Type
<?php
namespace Matiit\Bundle\BookBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BookType extends AbstractType
{
public function __construct($userId) {
$this->userId = $userId;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('length')
->add('file', 'file', array('required' => true))
->add('category', 'entity', array(
'class' => 'MatiitBookBundle:Category',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.userId = :userId')
->setParameter('userId', $this->userId);
},
))
->add('save', 'submit');
}
public function getName()
{
return 'book';
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Matiit\Bundle\BookBundle\Entity\Book',
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment