Permalink
Browse files

* setup.php zum Erzeugen des Datenbank-Schemas hinzugefügt

* Erstes Modell Person erzeugt
  • Loading branch information...
1 parent 8d573b6 commit a5dd997e1f3e0170ec99072b1f87d576cdeccfdb Marc Remolt committed Jun 21, 2010
Showing with 95 additions and 2 deletions.
  1. +69 −0 Models/Person.php
  2. +6 −1 config.inc.php
  3. +13 −1 index.php
  4. +7 −0 setup.php
View
@@ -0,0 +1,69 @@
+<?php
+namespace Models;
+
+/**
+ * @Entity
+ * @Table(name="personen")
+ */
+class Person
+{
+ /**
+ * @Id @Column(type="integer")
+ * @GeneratedValue
+ */
+ private $id;
+ /** @Column(type="string") */
+ private $vorname;
+ /** @Column(type="string") */
+ private $nachname;
+ /** @Column(type="date", nullable=true) */
+ private $geburtstag;
+ /** @Column(type="decimal", nullable=true) */
+ private $gewicht;
+
+ public function getId() {
+ return $this->id;
+ }
+
+ public function getVorname() {
+ return $this->vorname;
+ }
+
+ public function setVorname($vorname) {
+ $this->vorname = $vorname;
+ return $this;
+ }
+
+ public function getNachname() {
+ return $this->nachname;
+ }
+
+ public function setNachname($nachname) {
+ $this->nachname = $nachname;
+ return $this;
+ }
+
+ public function getGeburtstag() {
+ return $this->geburtstag;
+ }
+
+ public function setGeburtstag(\DateTime $geburtstag) {
+ $this->geburtstag = $geburtstag;
+ return $this;
+ }
+
+ public function getGewicht() {
+ return $this->gewicht;
+ }
+
+ public function setGewicht($gewicht) {
+ $this->gewicht = $gewicht;
+ return $this;
+ }
+
+ public function __toString() {
+ return $this->getVorname() . ' ' . $this->getNachname()
+ . ' (' . $this->getId() . ')';
+ }
+
+}
View
@@ -1,4 +1,7 @@
<?php
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
@@ -23,9 +26,11 @@
$connectionOptions = array(
'driver' => 'pdo_mysql',
+ 'dbname' => 'doctrine2_test',
'user' => 'root',
'password' => '',
- 'host' => 'localhost'
+ 'host' => 'localhost',
+ 'driverOptions' => array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )
);
$em = EntityManager::create($connectionOptions, $config);
View
@@ -1,4 +1,16 @@
<?php
require_once 'config.inc.php';
-var_dump($em);
+use Models\Person;
+
+$p1 = new Person();
+
+$p1->setVorname('Arthur')
+ ->setNachName('Dent')
+ ->setGeburtstag(new DateTime('1968-08-25'))
+ ->setGewicht(83);
+
+$em->persist($p1);
+$em->flush();
+
+echo $p1;
View
@@ -0,0 +1,7 @@
+<?php
+require_once 'config.inc.php';
+
+$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
+$metadata = $em->getMetadataFactory()->getAllMetadata();
+
+$schemaTool->updateSchema($metadata);

0 comments on commit a5dd997

Please sign in to comment.