Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created March 25, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/887463 to your computer and use it in GitHub Desktop.
Save Ocramius/887463 to your computer and use it in GitHub Desktop.
Doctrine 2 "Hello World" sample
<?php
/* ORM CONFIG HERE, LIKE IN SAMPLE BOOTSTRAP */
/** @var $em \Doctrine\ORM\EntityManager */
$em = Doctrine\ORM\EntityManager::create($options, $config);
$greeting = new Greeting();
$greeting->setGreeting('Hello World!');
$em->persist($greeting);
$greeting2 = new Greeting();
$greeting2->setGreeting('Hello again! This is another greeting!');
$em->persist($greeting2);
$em->flush();
$allGreetings = $em->createQuery('SELECT g FROM Greeting g')->getResult();
foreach($allGreetings as $greetMe) {
echo $greetMe->getGreeting() . '<br/>';
}
<?php
/**
* This class is somewhere in your library
* @Entity
* @Table(name="greetings")
*/
class Greeting {
/**
* @var int
* @Id
* @Column(type="integer",name="id")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @Column(type="string", length=60, name="greeting")
*/
protected $greeting;
public function getGreeting() {
return $this->greeting;
}
public function setGreeting($greeting) {
$this->greeting = (string) $greeting;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment