Skip to content

Instantly share code, notes, and snippets.

@jbalthis
Last active August 29, 2015 14:00
Show Gist options
  • Save jbalthis/e1c28bfd92f39ce30070 to your computer and use it in GitHub Desktop.
Save jbalthis/e1c28bfd92f39ce30070 to your computer and use it in GitHub Desktop.
Php method illustrating how to retrieve and pass data to be rendered
<?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