====== Doctrine 2 ======
Knihovna pro objektově relační mapování v PHP.
**Doctrine home page:** http://www.doctrine-project.org/
**Demo examples:** http://doctrine.isn.cz/
===== Požadavky =====
* miminálně PHP 5.3.0
===== Instalace pomocí Composeru =====
Protože mám v konfiguraci PHP (/etc/php.ini) volbu **allow_url_fopen=Off**, tak jsem do PHP CLI povolil hodnotu **On** pro stažení a instalaci.
**Stažení**
shell# mkdir -p /data/install/doctrine
shell# cd /data/install/doctrine
shell# curl -s http://getcomposer.org/installer | php -d allow_url_fopen=On
**Vytvoření konfiguračního souboru pro Composer**
Pro verzi Doctrine 2.3.4.
{
"require": {
"doctrine/orm": "2.3.4"
}
}
**Instalace přes Composer**
shell# php -d allow_url_fopen=On composer.phar install
===== Vrstvy =====
==== Common ====
**Namespace:** Doctrine\Common\\
**Doc:** http://docs.doctrine-project.org/projects/doctrine-common/en/latest/
* Class Loading
* Doctrine Annotations
* Doctrine Caching
==== DBAL (DataBase Abstraction Layer) ====
Včetně Common.
**Namespace:** Doctrine\DBAL\\
**Doc:** http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/
* PDO
* DQL (Doctrine Query Language)
==== ORM (Object-Relational Mapping) ====
Včetně Common a DBAL.
**Namespace:** Doctrine\ORM\\
**Doc:** http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/
===== MySQL DB =====
Vytvoření MySQL databáze a nastavení oprávnění.
shell# mysql -p -u root
mysql> CREATE DATABASE doctrinedemo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> GRANT ALL PRIVILEGES ON doctrinedemo.* TO doctrinedemo@localhost IDENTIFIED BY 'secretPassword';
mysql> FLUSH PRIVILEGES;
mysql> QUIT;
===== Příprava a konfigurace =====
Přejít do adresáře projektu.
shell# mkdir -p lib/doctrine
shell# cp -r /data/install/doctrine/vendor ./lib/doctrine
'pdo_mysql',
'user' => 'doctrinedemo',
'password' => 'secretPassword',
'dbname' => 'doctrinedemo',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
?>
===== Entity =====
id;
}
public function setId($id) {
$this->id = $id;
}
public function getFirstname() {
return $this->firstname;
}
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
public function getLastname() {
return $this->lastname;
}
public function setLastname($lastname) {
$this->lastname = $lastname;
}
public function getLogin() {
return $this->login;
}
public function setLogin($login) {
$this->login = $login;
}
public function getPassword() {
return $this->password;
}
public function setPassword($password) {
$this->password = $password;
}
public function getDescription() {
return $this->description;
}
public function setDescription($description) {
$this->description = $description;
}
public function getInsertDate() {
return $this->insertDate;
}
public function setInsertDate($insertDate) {
$this->insertDate = $insertDate;
}
}
?>
-- -----------------------------------------------------
-- Table `doctrinedemo`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `doctrinedemo`.`user` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(45) NULL,
`lastname` VARCHAR(45) NULL,
`login` VARCHAR(45) NOT NULL,
`password` VARCHAR(64) NOT NULL,
`description` TEXT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;