Skip to content

Commit

Permalink
* setup.php zum Erzeugen des Datenbank-Schemas hinzugefügt
Browse files Browse the repository at this point in the history
* Erstes Modell Person erzeugt
  • Loading branch information
Marc Remolt committed Jun 21, 2010
1 parent 8d573b6 commit a5dd997
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
69 changes: 69 additions & 0 deletions Models/Person.php
@@ -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() . ')';
}

}
7 changes: 6 additions & 1 deletion config.inc.php
@@ -1,4 +1,7 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Expand All @@ -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);
14 changes: 13 additions & 1 deletion index.php
@@ -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;
7 changes: 7 additions & 0 deletions setup.php
@@ -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.