Simfony 2: Mapear Base de datos con Doctrine
Dando por hecho que ya tenemos una base de datos con sus tablas y que el archivo app/config/parameters.ini está correctamente configurado:
Vamos al directorio raíz de nuestro proyecto Symfony y escribimos en un terminal lo siguiente:
1 |
php app/console doctrine:mapping:convert yml ./src/BlueCMS/Bundle/BlueCMSBundle/Resources/config/doctrine/metadata/orm --from-database --force |
Donde, ‘yml’ es el formato de los archivos orm, (que pueden ser yml/xml/php).
Salida:
1 |
<br /> ./src/BlueCMS/Bundle/BlueCMSBundle/Resources/config/doctrine/metadata/orm --from-database --force<br />Processing entity "Comment"<br />Processing entity "Entry"<br />Processing entity "Module"<br />Processing entity "Settings"<br />Processing entity "User"<br /><br />Exporting "yml" mapping information to "/home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Resources/config/doctrine/metadata/orm"<br /> |
Donde, ‘BlueCMS’, es nuestro proyecto, y BlueCMSBundle el bundle de nuestro proyecto.
2º:
1 |
php app/console doctrine:mapping:import BlueCMSBundle annotation<br /> |
Salida:
1 |
Importing mapping information from "default" entity manager<br /> > writing /home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Entity/Comment.php<br /> > writing /home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Entity/Entry.php<br /> > writing /home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Entity/Module.php<br /> > writing /home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Entity/Settings.php<br /> > writing /home/cristian/GIT/BlueCMS/src/BlueCMS/Bundle/BlueCMSBundle/Entity/User.php<br /> |
3º:
1 |
php app/console doctrine:mapping:import BlueCMSBundle annotation<br /> |
Salida:
1 |
Generating entities for bundle "BlueCMSBundle"<br /> > backing up Settings.php to Settings.php~<br /> > generating BlueCMSBundleBlueCMSBundleEntitySettings<br /> > backing up Comment.php to Comment.php~<br /> > generating BlueCMSBundleBlueCMSBundleEntityComment<br /> > backing up User.php to User.php~<br /> > generating BlueCMSBundleBlueCMSBundleEntityUser<br /> > backing up Module.php to Module.php~<br /> > generating BlueCMSBundleBlueCMSBundleEntityModule<br /> > backing up Entry.php to Entry.php~<br /> > generating BlueCMSBundleBlueCMSBundleEntityEntry<br /> |
Fuente: http://symfony.com/doc/2.0/cookbook/doctrine/reverse_engineering.html