Mapping Entities Using XML

To map the Order Entity using the XML mapping, the setup code of Doctrine should be altered slightly:

require_once '/path/to/vendor/autoload.php';

use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;

$paths = ['/path/to/mapping-files'];
$isDevMode = false;

// the connection configuration
$dbParams = [
'driver' => 'pdo_mysql',
'user' => 'the_database_username',
'password' => 'the_database_password',
'dbname' => 'the_database_name',
];

$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);

The mapping file should be created on the path where Doctrine will search for the mapping files, and the mapping files should be named after the fully qualified class name, replacing the backslashes with dots. Consider the following:

AcmeBillingDomainModelOrder

The preceding illustration would have the mapping file named like this:

Acme.Billing.Domain.Model.Order.dcm.xml

Additionally, it's convenient that all the mapping files use a special XML Schema created specially for specifying mapping information:

https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset