-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultController.php
66 lines (52 loc) · 2.22 KB
/
DefaultController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Acme\TestBundle\Controller;
use Acme\TestBundle\Entity\Product;
use Acme\TestBundle\Entity\ProductKeys;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\EntityRepository;
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$repository = $this->getDoctrine()->getRepository('AcmeTestBundle:Product');
$products = $repository->findAll();
// создаём задачу и присваиваем ей некоторые начальные данные для примера
$task = new Product();
//$task->setDescription(array('Write a blog post','Write a blog post','Write a blog post'));
// $task->setDueDate(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
/* ->add('races', 'entity', array('label' => 'Категория',
'class' => 'AcmeTestBundle:Test1','property' => 'id',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('p')
->orderBy('p.id', 'DESC');
},'multiple' => true,"expanded" => true,'compound'=>3,
))*/
/*->add('roles', 'choice', array(
'choices' => array('Foo' => 'Foo', 'Bar' => 'Bar', 'Baz' => 'Baz'),
'empty_value' => 'Choose your gender','required'=>false,'empty_data' => 0,"expanded" => true,'multiple' => true,
))*/
->add('categories', 'collection', array(
'type' => 'entity',
'options' => array(
'class' => 'AcmeTestBundle:Test1','property' => 'id',
'required' => true,
'attr' => array('class' => 'email-box')
),
))
->add('name', 'text')
->add('save', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
// perform some action, such as saving the task to the database
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
}
return $this->render('AcmeTestBundle:Default:index.html.twig', array(
'form' => $form->createView(),'products'=>$products
));
}
}