Last active
August 29, 2015 14:00
-
-
Save jbalthis/e1c28bfd92f39ce30070 to your computer and use it in GitHub Desktop.
Php method illustrating how to retrieve and pass data to be rendered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* An example method with Symfony2 style routing config'd via annotation | |
* Illustrating how to use either a supplied param or a GET request key:value | |
* To retrieve and pass data to be rendered | |
*/ | |
// ... ... ... | |
// Controller class declaration and other logic | |
// ... ... ... | |
/** | |
* @Route("/show") | |
*/ | |
public function showAction($id) | |
{ | |
// to show a query via defined param | |
$repo = $this->getDoctrine() | |
->getRepository('JbalthisExampleBundle:Job'); | |
$job_via_param = $repo->find($id); | |
// to show a GET http req defined key:val | |
$req = new Request(); | |
$job_via_req_id = $req->get('id'); | |
// simple logic just to illustrate concept | |
if($job_via_param){ | |
return new Response($job_via_param.' job came from a defined method param'); | |
} | |
else if($job_via_req_id){ | |
return new Response($repo->find($job_via_req_id)." job came from a GET request id"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment