Advertisement
Guest User

Hello world dengan Symfony 2.7

a guest
Sep 7th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. namespace AppBundle\Controller;
  3.  
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8.  
  9. class HelloWorldController extends Controller {
  10.    
  11.     /**
  12.      * @Route("/greating")
  13.      */
  14.     public function greatingAction()
  15.     {
  16.         return new Response(
  17.                 '<html><body>Hello World</body></html>'
  18.         );
  19.     }
  20.    
  21.     /**
  22.      * @Route("/greating.json")
  23.      */
  24.     public function greating2Action()
  25.     {
  26.         $data = array(
  27.             'message' => "Hello World",
  28.         );
  29.  
  30.         return new Response(
  31.             json_encode($data),
  32.             200,
  33.             array('Content-Type' => 'application/json')
  34.         );
  35.     }
  36.    
  37.     /**
  38.      * @Route("/greating.simple.json")
  39.      */
  40.     public function greating3Action()
  41.     {
  42.         $data = array(
  43.                 'message' => "Hello World",
  44.         );
  45.    
  46.          return new JsonResponse($data);
  47.     }
  48.    
  49.     //now with parameter
  50.     /**
  51.      * @Route("/xgreating/{count}")
  52.      */
  53.     public function greating4Action($count)
  54.     {
  55.         $msg = "";
  56.         for($x=0;$x<$count;$x++) {
  57.             $msg .= 'Hello World '.$x.' <br/>';
  58.         }
  59.        
  60.         return new Response(
  61.                 '<html><body>'.$msg.'</body></html>'
  62.         );
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement