Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\JsonResponse;
- class HelloWorldController extends Controller {
- /**
- * @Route("/greating")
- */
- public function greatingAction()
- {
- return new Response(
- '<html><body>Hello World</body></html>'
- );
- }
- /**
- * @Route("/greating.json")
- */
- public function greating2Action()
- {
- $data = array(
- 'message' => "Hello World",
- );
- return new Response(
- json_encode($data),
- 200,
- array('Content-Type' => 'application/json')
- );
- }
- /**
- * @Route("/greating.simple.json")
- */
- public function greating3Action()
- {
- $data = array(
- 'message' => "Hello World",
- );
- return new JsonResponse($data);
- }
- //now with parameter
- /**
- * @Route("/xgreating/{count}")
- */
- public function greating4Action($count)
- {
- $msg = "";
- for($x=0;$x<$count;$x++) {
- $msg .= 'Hello World '.$x.' <br/>';
- }
- return new Response(
- '<html><body>'.$msg.'</body></html>'
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement