Installation and Configuration ============================== Doctrine can be installed with `Composer <https://getcomposer.org>`_. Define the following requirement in your ``composer.json`` file: :: { "require": { "doctrine/orm": "*" } } Then call ``composer install`` from your command line. If you don't know how Composer works, check out their `Getting Started <https://getcomposer.org/doc/00-intro.md>`_ to set up. Class loading ------------- Autoloading is taken care of by Composer. You just have to include the composer autoload file in your project: .. code-block:: php <?php // bootstrap.php // Include Composer Autoload (relative to project root). require_once "vendor/autoload.php"; Obtaining an EntityManager -------------------------- Once you have prepared the class loading, you acquire an *EntityManager* instance. The EntityManager class is the primary access point to ORM functionality provided by Doctrine. .. code-block:: php <?php // bootstrap.php require_once "vendor/autoload.php"; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; $paths = array("/path/to/entity-files"); $isDevMode = false; // the connection configuration $dbParams = array( 'driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'foo', ); $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); $entityManager = EntityManager::create($dbParams, $config); Or if you prefer XML: .. code-block:: php <?php $paths = array("/path/to/xml-mappings"); $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode); $entityManager = EntityManager::create($dbParams, $config); Or if you prefer YAML: .. code-block:: php <?php $paths = array("/path/to/yml-mappings"); $config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode); $entityManager = EntityManager::create($dbParams, $config); .. note:: If you want to use yml mapping you should add yaml dependency to your `composer.json`: :: "symfony/yaml": "*" Inside the ``Setup`` methods several assumptions are made: - If `$isDevMode` is true caching is done in memory with the ``ArrayCache``. Proxy objects are recreated on every request. - If `$isDevMode` is false, check for Caches in the order APC, Xcache, Memcache (127.0.0.1:11211), Redis (127.0.0.1:6379) unless `$cache` is passed as fourth argument. - If `$isDevMode` is false, set then proxy classes have to be explicitly created through the command line. - If third argument `$proxyDir` is not set, use the systems temporary directory. If you want to configure Doctrine in more detail, take a look at the :doc:`Advanced Configuration <reference/advanced-configuration>` section. .. note:: You can learn more about the database connection configuration in the `Doctrine DBAL connection configuration reference <http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html>`_. Setting up the Commandline Tool ------------------------------- Doctrine ships with a number of command line tools that are very helpful during development. You can call this command from the Composer binary directory: .. code-block:: sh $ php vendor/bin/doctrine You need to register your applications EntityManager to the console tool to make use of the tasks by creating a ``cli-config.php`` file with the following content: On Doctrine 2.4 and above: .. code-block:: php <?php use Doctrine\ORM\Tools\Console\ConsoleRunner; // replace with file to your own project bootstrap require_once 'bootstrap.php'; // replace with mechanism to retrieve EntityManager in your app $entityManager = GetEntityManager(); return ConsoleRunner::createHelperSet($entityManager); On Doctrine 2.3 and below: .. code-block:: php <?php // cli-config.php require_once 'my_bootstrap.php'; // Any way to access the EntityManager from your application $em = GetMyEntityManager(); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) ));
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
advanced-configuration.rst | File | 16.18 KB | 0644 |
|
annotations-reference.rst | File | 37.16 KB | 0644 |
|
architecture.rst | File | 7.52 KB | 0644 |
|
association-mapping.rst | File | 31.32 KB | 0644 |
|
basic-mapping.rst | File | 17.24 KB | 0644 |
|
batch-processing.rst | File | 5.77 KB | 0644 |
|
best-practices.rst | File | 3.61 KB | 0644 |
|
caching.rst | File | 13.24 KB | 0644 |
|
change-tracking-policies.rst | File | 5.13 KB | 0644 |
|
configuration.rst | File | 4.29 KB | 0644 |
|
dql-doctrine-query-language.rst | File | 60.95 KB | 0644 |
|
events.rst | File | 30.98 KB | 0644 |
|
faq.rst | File | 9.95 KB | 0644 |
|
filters.rst | File | 3.38 KB | 0644 |
|
improving-performance.rst | File | 2.66 KB | 0644 |
|
inheritance-mapping.rst | File | 20.79 KB | 0644 |
|
installation.rst | File | 131 B | 0644 |
|
limitations-and-known-issues.rst | File | 7.66 KB | 0644 |
|
metadata-drivers.rst | File | 6.02 KB | 0644 |
|
namingstrategy.rst | File | 4.38 KB | 0644 |
|
native-sql.rst | File | 34.31 KB | 0644 |
|
partial-objects.rst | File | 3.52 KB | 0644 |
|
php-mapping.rst | File | 8.82 KB | 0644 |
|
query-builder.rst | File | 20.6 KB | 0644 |
|
second-level-cache.rst | File | 24.02 KB | 0644 |
|
security.rst | File | 4.68 KB | 0644 |
|
tools.rst | File | 16.8 KB | 0644 |
|
transactions-and-concurrency.rst | File | 13.9 KB | 0644 |
|
unitofwork-associations.rst | File | 2.74 KB | 0644 |
|
unitofwork.rst | File | 6.73 KB | 0644 |
|
working-with-associations.rst | File | 22.24 KB | 0644 |
|
working-with-objects.rst | File | 31.61 KB | 0644 |
|
xml-mapping.rst | File | 27.11 KB | 0644 |
|
yaml-mapping.rst | File | 4.42 KB | 0644 |
|