Skip to content

Instantly share code, notes, and snippets.

@jbalthis
Created April 30, 2014 21:03
Show Gist options
  • Save jbalthis/566949230dab91ca3afe to your computer and use it in GitHub Desktop.
Save jbalthis/566949230dab91ca3afe to your computer and use it in GitHub Desktop.
Taking a GET req into a method and persisting a new obj to a db using the Doctrine ORM and annotations in PHP
<?php
/*
* Example of taking a GET req into a method and persisting a new obj to a db
* using the Doctrine ORM and annotations in PHP
*/
// ... ... ...
// Controller class declaration and misc logic
// ... ... ...
/**
* @Route("/create")
*/
public function createAction(){
// get req to grab short name
$req = new Request();
$slug = $req->get('slug');
// timestamp
$now = date('Y-m-d_H.i.s');
// create new Job obj
$job = new Job();
// set jobId
$job->setJobId($slug.$now);
// persist
$em = $this->getDoctrine()->getManager();
$em->persist($job);
$em->flush();
return new Response('Created a new Job with short name'.$slug.' and jobId '.$slug.$now);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment