Update getting-started.rst
The inline cli-config.php, bootstrap.php examples were out of sync with Doctrine 2.4.x — I referenced https://github.com/doctrine/doctrine2-orm-tutorial/ for correct examples
This commit is contained in:
parent
605c32dbb3
commit
3405659eba
@ -25,7 +25,7 @@ The code of this tutorial is `available on Github <https://github.com/doctrine/d
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
This tutorial assumes you work with Doctrine 2.4 and above.
|
This tutorial assumes you work with **Doctrine 2.4** and above.
|
||||||
Some of the code will not work with lower versions.
|
Some of the code will not work with lower versions.
|
||||||
|
|
||||||
What is Doctrine?
|
What is Doctrine?
|
||||||
@ -102,19 +102,33 @@ Install Doctrine using the Composer Dependency Management tool, by calling:
|
|||||||
$ composer install
|
$ composer install
|
||||||
|
|
||||||
This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM,
|
This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM,
|
||||||
Symfony YAML and Symfony Console. Both Symfony dependencies are optional
|
Symfony YAML and Symfony Console into the `vendor` directory. The Symfony
|
||||||
but will be used in this tutorial.
|
dependencies are not required by Doctrine but will be used in this tutorial.
|
||||||
|
|
||||||
You can prepare the directory structure:
|
This is the current directory structure:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
project
|
doctrine2-tutorial
|
||||||
|
|-- composer.json
|
||||||
|
`-- vendor
|
||||||
|
|
||||||
|
Next we'll create a basic bootsrapped application that uses the Symfony
|
||||||
|
Console to interact with Doctrine via the command line.
|
||||||
|
|
||||||
|
Here's a preview of what we'll add:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
doctrine2-tutorial
|
||||||
|
|-- bootstrap.php
|
||||||
|
|-- cli-config.php
|
||||||
|-- composer.json
|
|-- composer.json
|
||||||
|-- config
|
|-- config
|
||||||
| |-- xml
|
| |-- xml
|
||||||
| `-- yaml
|
| `-- yaml
|
||||||
`-- src
|
|-- src
|
||||||
|
`-- vendor
|
||||||
|
|
||||||
Obtaining the EntityManager
|
Obtaining the EntityManager
|
||||||
---------------------------
|
---------------------------
|
||||||
@ -131,14 +145,13 @@ step:
|
|||||||
<?php
|
<?php
|
||||||
// bootstrap.php
|
// bootstrap.php
|
||||||
use Doctrine\ORM\Tools\Setup;
|
use Doctrine\ORM\Tools\Setup;
|
||||||
use Doctrine\ORM\EntityManager;
|
|
||||||
|
|
||||||
require_once "vendor/autoload.php";
|
require_once "vendor/autoload.php";
|
||||||
|
|
||||||
// Create a simple "default" Doctrine ORM configuration for Annotations
|
// Create a simple "default" Doctrine ORM configuration for XML Mapping
|
||||||
$isDevMode = true;
|
$isDevMode = true;
|
||||||
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
|
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
|
||||||
// or if you prefer yaml or XML
|
// or if you prefer yaml or annotations
|
||||||
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
|
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
|
||||||
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
|
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
|
||||||
|
|
||||||
@ -149,7 +162,7 @@ step:
|
|||||||
);
|
);
|
||||||
|
|
||||||
// obtaining the entity manager
|
// obtaining the entity manager
|
||||||
$entityManager = EntityManager::create($conn, $config);
|
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
|
||||||
|
|
||||||
The first require statement sets up the autoloading capabilities of Doctrine
|
The first require statement sets up the autoloading capabilities of Doctrine
|
||||||
using the Composer autoload.
|
using the Composer autoload.
|
||||||
@ -187,7 +200,9 @@ doctrine command. Its a fairly simple file:
|
|||||||
// cli-config.php
|
// cli-config.php
|
||||||
require_once "bootstrap.php";
|
require_once "bootstrap.php";
|
||||||
|
|
||||||
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
|
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
|
||||||
|
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)
|
||||||
|
));
|
||||||
|
|
||||||
You can then change into your project directory and call the
|
You can then change into your project directory and call the
|
||||||
Doctrine command-line tool:
|
Doctrine command-line tool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user