Created
December 6, 2012 10:39
-
-
Save webmozart/4223579 to your computer and use it in GitHub Desktop.
Symfony Issue 6190
This file contains 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 Webmozart\TestBundle\Controller; | |
use Symfony\Component\HttpFoundation\Request; | |
use Webmozart\TestBundle\Form\Issue6190EntityType; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
/** | |
* https://github.com/symfony/symfony/issues/6190 | |
* | |
* @author Bernhard Schussek <bschussek@gmail.com> | |
*/ | |
class Issue6190Controller extends Controller | |
{ | |
/** | |
* @Route("/6190", name="issue6190") | |
* @Template() | |
*/ | |
public function testAction(Request $request) | |
{ | |
$type = new Issue6190EntityType(); | |
$form = $this->createFormBuilder() | |
->add('entity1', $type, array( | |
'order' => 'ASC', | |
)) | |
->add('entity2', $type, array( | |
'order' => 'DESC', | |
)) | |
->getForm(); | |
return array('form' => $form->createView()); | |
} | |
} |
This file contains 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 Webmozart\TestBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
*/ | |
class Issue6190Entity | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
public $id; | |
/** | |
* @ORM\Column(type="string") | |
*/ | |
public $name; | |
public function __construct($name) | |
{ | |
$this->name = $name; | |
} | |
} |
This file contains 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 Webmozart\TestBundle\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\OptionsResolver\Options; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
class Issue6190EntityType extends AbstractType | |
{ | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'class' => 'Webmozart\TestBundle\Entity\Issue6190Entity', | |
'property' => 'name', | |
'order' => 'DESC', | |
'choices' => function (Options $options) { | |
/** @var \Doctrine\ORM\QueryBuilder $qb */ | |
$qb = $options['em']->getRepository($options['class'])->createQueryBuilder('c'); | |
$qb->addOrderBy('c.name', $options['order']); | |
return $qb->getQuery()->getResult(); | |
} | |
)); | |
} | |
public function getParent() | |
{ | |
return 'entity'; | |
} | |
public function getName() | |
{ | |
return 'issue5582_entity'; | |
} | |
} |
This file contains 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
<form action="{{ path('issue6190') }}" method="post" {{ form_enctype(form) }}> | |
{{ form_widget(form) }} | |
<input type="submit" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment