3
3
namespace AppBundle \Controller ;
4
4
5
5
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
6
-
6
+ use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Method ;
7
7
use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
8
+ use Symfony \Component \HttpFoundation \JsonResponse ;
8
9
use Symfony \Component \HttpFoundation \Response ;
9
10
10
11
class GenusController extends Controller
@@ -14,17 +15,39 @@ class GenusController extends Controller
14
15
*/
15
16
public function showAction ($ genusName )
16
17
{
17
- $ notes = [
18
- 'Octopus asked me a riddle, outsmarted me ' ,
19
- 'I counted 8 legs... as they wrapped around me ' ,
20
- 'Inked! '
21
- ];
18
+ ////// $notes = [
19
+ ////// 'Octopus asked me a riddle, outsmarted me',
20
+ ////// 'I counted 8 legs... as they wrapped around me',
21
+ ////// 'Inked!'
22
+ ////// ];
23
+
24
+
22
25
//// return new Response("Under the sea!!!! Oh Yeah!!! <br/> The genus: ".$genusName);
23
26
// $templating = $this->container->get('templating');
24
27
//// $this->container->get('templating')
25
28
// $html = $templating->render('genus/show.html.twig', array('name' => $genusName));
26
29
//
27
30
// return new Response($html);
28
- return $ this ->render ('genus/show.html.twig ' , array ('name ' => $ genusName , 'notes ' => $ notes ));
31
+ return $ this ->render ('genus/show.html.twig ' , array ('name ' => $ genusName ));
32
+ }
33
+
34
+ /**
35
+ * @Route("/genus/{genusName}/notes")
36
+ * @Method("GET")
37
+ */
38
+ public function getNotesAction ($ genusName )
39
+ {
40
+ $ notes = [
41
+ ['id ' => 1 , 'username ' => 'AquaPelham ' , 'avatarUri ' => '/images/leanna.jpeg ' , 'note ' => 'Octopus asked me a riddle, outsmarted me ' , 'date ' => 'Dec. 10, 2015 ' ],
42
+ ['id ' => 2 , 'username ' => 'AquaWeaver ' , 'avatarUri ' => '/images/ryan.jpeg ' , 'note ' => 'I counted 8 legs... as they wrapped around me ' , 'date ' => 'Dec. 1, 2015 ' ],
43
+ ['id ' => 3 , 'username ' => 'AquaPelham ' , 'avatarUri ' => '/images/leanna.jpeg ' , 'note ' => 'Inked! ' , 'date ' => 'Aug. 20, 2015 ' ],
44
+ ];
45
+
46
+ $ data = [
47
+ 'notes ' => $ notes
48
+ ];
49
+
50
+ // return new Response(json_encode($data)); //está retornando os dados como json
51
+ return new JsonResponse ($ data ); //também retorna os dados como json
29
52
}
30
53
}
0 commit comments