1
0
mirror of synced 2025-02-21 14:43:14 +03:00

Worked on the Getting Started Guide

This commit is contained in:
Benjamin Eberlei 2013-03-17 12:26:34 +01:00
parent a7d764f6c0
commit 5941d0267d

View File

@ -796,16 +796,17 @@ step:
.. code-block:: php
<?php
// bootstrap_doctrine.php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
// See :doc:`Configuration <../reference/configuration>` for up to date autoloading details.
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for XML Mapping
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
// or if you prefer yaml or annotations
//$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/entities"), $isDevMode);
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/entities"), $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
@ -815,15 +816,13 @@ step:
);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
$entityManager = EntityManager::create($conn, $config);
The first require statement sets up the autoloading capabilities of Doctrine.
We assume here that you have installed Doctrine using Composer.
See :doc:`Configuration <../reference/configuration>` for more details
on other installation procedures.
The first require statement sets up the autoloading capabilities of Doctrine
using the Composer autoload.
The second block consists of the instantiation of the ORM
Configuration object using the Setup helper. It assumes a bunch
``Configuration`` object using the Setup helper. It assumes a bunch
of defaults that you don't have to bother about for now. You can
read up on the configuration details in the
:doc:`reference chapter on configuration <../reference/configuration>`.
@ -833,35 +832,9 @@ to a database, in my case a file-based sqlite database. All the
configuration options for all the shipped drivers are given in the
`DBAL Configuration section of the manual <http://www.doctrine-project.org/documentation/manual/2_0/en/dbal>`_.
You should make sure to make it configurable if Doctrine should run
in dev or production mode using the `$devMode` variable. You can
use an environment variable for example, hook into your frameworks configuration
or check for the HTTP_HOST of your devsystem (localhost for example)
.. code-block:: php
<?php
// examples, use your own logic to determine this:
$isDevMode = ($_SERVER['HTTP_HOST'] == 'localhost');
$isDevMode = ($_ENV['APPLICATION_ENV'] == 'development');
The last block shows how the ``EntityManager`` is obtained from a
factory method.
We also have to create a general bootstrap file for our application:
.. code-block:: php
<?php
// bootstrap.php
if (!class_exists("Doctrine\Common\Version", false)) {
require_once "bootstrap_doctrine.php";
}
require_once "entities/User.php";
require_once "entities/Product.php";
require_once "entities/Bug.php";
Generating the Database Schema
------------------------------
@ -891,19 +864,7 @@ Doctrine command-line tool:
::
$ cd project/
$ php vendor/bin/doctrine-orm orm:schema-tool:create
.. note::
The ``doctrine`` command will only be present if you installed
Doctrine from Composer. Otherwise you will have to dig into the
``bin/doctrine.php`` code of your Doctrine 2 directory to setup
your doctrine command-line client.
See the
:doc:`Tools section of the manual <../reference/tools>`
on how to setup the Doctrine console correctly.
$ php vendor/bin/doctrine orm:schema-tool:create
During the development you probably need to re-create the database
several times when changing the Entity metadata. You can then
@ -911,14 +872,14 @@ either re-create the database:
::
$ doctrine orm:schema-tool:drop --force
$ doctrine orm:schema-tool:create
$ php vendor/bin/doctrine orm:schema-tool:drop --force
$ php vendor/bin/doctrine orm:schema-tool:create
Or use the update functionality:
::
$ doctrine orm:schema-tool:update --force
$ php vendor/bin/doctrine orm:schema-tool:update --force
The updating of databases uses a Diff Algorithm for a given
Database Schema, a cornerstone of the ``Doctrine\DBAL`` package,