-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDefaultController.php
85 lines (62 loc) · 2.6 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Iphp\FileStoreBundle\Tests\Functional\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Iphp\FileStoreBundle\Form\Type\FileType as IphpFileType;
use Symfony\Component\HttpFoundation\Request;
use Iphp\FileStoreBundle\Tests\Functional\TestBundle\Entity\Photo;
/**
* @author Vitiko <vitiko@mail.ru>
*/
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$photo = new Photo();
$uploadForm = $this->get('form.factory')->createNamedBuilder(null, FormType::class, $photo,
array('csrf_protection' => false))
->add('title', TextType::class)
->add('date', DateType::class)
//Using standart field type
->add('photo', FileType::class)
->add('photoUpload', FileType::class)
->getForm();
$uploadForm->handleRequest($request);
if ($uploadForm->isSubmitted() && $uploadForm->isValid()) {
$em->persist($photo);
$em->flush();
return $this->redirect($this->generateUrl('photo_index'));
}
return $this->render('TestBundle:Photo:index.html.twig', array(
'uploadForm' => $uploadForm->createView(),
'photos' => $em->getRepository('TestBundle:Photo')->findAll()
));
}
public function editAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$photo = $em->getRepository('TestBundle:Photo')->findOneById($id);
$editForm = $this->createFormBuilder($photo)
->add('title', TextType::class)
->add('date', DateType::class)
//Using field type with showing file/image info
->add('photo', IphpFileType::class)
->add('photoUpload', FileType::class)
->add('photoInfo', IphpFileType::class)
->getForm();
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em->persist($photo);
$em->flush();
return $this->redirect($this->generateUrl('photo_edit', array('id' => $photo->getId())));
}
return $this->render('TestBundle:Photo:edit.html.twig', array(
'photo' => $photo,
'editForm' => $editForm->createView(),
));
}
}