1 | <?php |
||
13 | class DefaultController extends Controller |
||
14 | { |
||
15 | /** |
||
16 | * @param $templateName |
||
17 | * |
||
18 | * @return \Symfony\Component\HttpFoundation\Response |
||
19 | * |
||
20 | * @Route("/default/{templateName}.{_format}", name="test_default", defaults={"templateName" = "simple", "_format" = "xlsx"}) |
||
21 | */ |
||
22 | public function defaultAction($templateName): Response |
||
23 | { |
||
24 | return $this->render( |
||
25 | '@Test/Default/'.$templateName.'.twig', |
||
26 | [ |
||
27 | 'data' => [ |
||
28 | ['name' => 'Everette Grim', 'salary' => 5458.0], |
||
29 | ['name' => 'Nam Poirrier', 'salary' => 3233.0], |
||
30 | ['name' => 'Jolynn Ell', 'salary' => 5718.0], |
||
31 | ['name' => 'Ta Burdette', 'salary' => 1255.0], |
||
32 | ['name' => 'Aida Salvas', 'salary' => 5226.0], |
||
33 | ['name' => 'Gilbert Navarrette', 'salary' => 1431.0], |
||
34 | ['name' => 'Kirk Figgins', 'salary' => 7429.0], |
||
35 | ['name' => 'Rashad Cloutier', 'salary' => 8457.0], |
||
36 | ['name' => 'Traci Schmitmeyer', 'salary' => 7521.0], |
||
37 | ['name' => 'Cecila Statham', 'salary' => 7180.0], |
||
38 | ['name' => 'Chong Robicheaux', 'salary' => 3511.0], |
||
39 | ['name' => 'Romona Stockstill', 'salary' => 2943.0], |
||
40 | ['name' => 'Roseann Sather', 'salary' => 9126.0], |
||
41 | ['name' => 'Vera Racette', 'salary' => 4566.0], |
||
42 | ['name' => 'Tennille Waltripv', 'salary' => 4485.0], |
||
43 | ['name' => 'Dot Hedgpeth', 'salary' => 7687.0], |
||
44 | ['name' => 'Thersa Havis', 'salary' => 2264.0], |
||
45 | ['name' => 'Long Kenner', 'salary' => 4051.0], |
||
46 | ['name' => 'Kena Kea', 'salary' => 4090.0], |
||
47 | ['name' => 'Evita Chittum', 'salary' => 4639.0], |
||
48 | ], |
||
49 | 'kernelPath' => $this->get('kernel')->getRootDir(), |
||
50 | ] |
||
51 | ); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param $templateName |
||
56 | * |
||
57 | * @throws \InvalidArgumentException |
||
58 | * |
||
59 | * @return \Symfony\Component\HttpFoundation\Response |
||
60 | * |
||
61 | * @Route("/custom-response/{templateName}.{_format}", name="test_custom_response", defaults={"templateName" = "simple", "_format" = "xlsx"}) |
||
62 | */ |
||
63 | public function customResponseAction($templateName): Response |
||
64 | { |
||
65 | $response = new Response( |
||
66 | $this->render( |
||
67 | '@Test/Default/'.$templateName.'.twig', |
||
68 | [ |
||
69 | 'data' => [ |
||
70 | ['name' => 'Everette Grim', 'salary' => 5458.0], |
||
71 | ['name' => 'Nam Poirrier', 'salary' => 3233.0], |
||
72 | ['name' => 'Jolynn Ell', 'salary' => 5718.0], |
||
73 | ], |
||
74 | ] |
||
75 | ) |
||
76 | ); |
||
77 | |||
78 | $response->headers->set('Content-Disposition', $response->headers->makeDisposition( |
||
79 | ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
||
80 | 'foobar.bin' |
||
81 | )); |
||
82 | $response->setMaxAge(600); |
||
83 | |||
84 | return $response; |
||
85 | } |
||
86 | } |
||
87 |