Ambiguous Tutorial - Getting Started with Doctrine - php

I'm trying to work through this tutorial.
http://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started.html
But get stuck at the point where I have to create the schema.
php vendor/bin/doctrine orm:schema-tool:create
Always getting:
No Metadata Classes to process.
I tried the solutions presented by the following post in vain:
Doctrine2 - No Metadata Classes to process
and
Doctrine2: Getting Started Tutorial "No Metadata Classes to process"
Any suggestions ? I'm stuck here for about three hours :-/

Metadata for entities are configured using a XML, YAML or Docblock
Annotations. This Getting Started Guide will show the mappings for all
Mapping Drivers. References in the text will be made to the XML
mapping.
Maybe I misunderstood. But when I read
References in the text will be made to the XML mapping
I used the XML file to configure the metadata. But I should have used the Docblock Annotations, that's all I had to do.

Related

Symfony2: How to generate Entities from MULTIPLE Existing Databases in SAME Bundle?

My goal is to get access to multiple databases in One Project Bundle.
I read through the symfony2 docs and managed to do the followings:
configure multiple connections for different Bundles
generate Entities from ONE Existing Database using:
php app/console doctrine:mapping:import AcmeBlogBundle annotation
php app/console doctrine:generate:entities AcmeBlogBundle
But I cannot find ways to generate Entities from MULTIPLE Existing Databases in SAME Bundle so that I can access multiple databases in One Bundle. Any Ideas?
P.S. I am not familiar with Doctrine. So actually if there are ways to do Symfony2 without Doctrine, I would also appreciate.
UPDATE #1:
Cerad's answer comes quite close. Yet one problem is not yet solved. As I have some same table names in different databases, it's better to organised them into separte folders inside Entity Folder. I have checked similar posts like this and that. But the solutions are not working for me. Their solution simply puts all entities directly into Entity Folder, ignoring the specified dir option in config.yml. Are there workarounds for this problem?
The first step it to configure multiple entity managers (not connections), one for each database. You then use the --em option on the doctrine commands to specify which entity manager to use.
php app/console doctrine:mapping:import "AcmeBlogBundle" annotation --em=name1
php app/console doctrine:mapping:import "AcmeBlogBundle" annotation --em=name2
Be aware that you not going to be able to directly query (join) across multiple database with doctrine. At least not very easily. As long as you plan on limiting your queries to one database at a time then you will be fine.
This is actually a somewhat advanced topic. You might want to spend some time with the doctrine documentation. Might also be easier to get started with one database and then split later.

Doctrine 2 mapping - cant auto generate yml files

I'm trying to get doctrine 2 work for me (I used to work with d1)
but I can't get doctrine generate the models (like on doctrine1)
I have downloaded the lastest version of doctrine 2.1
so my directory tree looks like that :
C:\doctrine\bin - got it from the tar file
C:\doctrine\Doctrine - got it from the tar file
C:\doctrine\models - created by me for mapping info
I also edited the bin doctrine.php file and added cli-config.php file and its looking like that:
C:\doctrine\bin\doctrine.php --> http://pastebin.com/Ki62hbTX
C:\doctrine\bin\cli-config.php --> http://pastebin.com/cPv4fXX1
Now when I'm going to cmd this is the result:
c:\doctrine\bin>php doctrine orm:schema-tool:create
No Metadata Classes to process.
I checked the paths of files, write permissions, db login info and every thing but I can't find out how to read db and generate the class
any idea will be great, thanks
There might be several problems here, but let me start by saying that I just moved to doctrine2 from 1.2 and it is way easier to use php annotations in doctrine2. Then you're creating the class yourself....everything just seems to make sense a little more.
But, if you want to use YAML, be aware that with YAML and Doctrine2, the YAML hierarchy is completely different. So you can't just load your doctrine1 yaml into doctrine2.
Here's the guide to YAML in doctrine 2: http://www.doctrine-project.org/docs/orm/2.0/en/reference/yaml-mapping.html
The one thing that I found is that Doctrine2 wanted a specific folder for my namespace. So my entities are in entities/NAMESPACE/ rather than just entities/. Also note that you need a separate file for each class and the naming conventions are very strict.

Is it possible to generate model classes using Doctrine 2 directly from the database?

I am in the process of upgrading from Doctrine 1.1.4 to Doctrine 2.0.6 in my Zend application. I have installed the Doctrine 2 command line tool.
In Doctrine 1.1.4, I generated the model classes directly from the database (using Doctrine::generateModelsFromDb()), is this possible in Doctrine 2, or do I have to go through the 'mapping' process i.e. by providing Docblock Annotations, XML or YAML structures of the tables.
The reason I ask this is because there is a 'setAutoGenerateProxyClass' option in Doctrine 2, I got the impression that this means it will generate the proxy classes from scratch.
Appreciate the help.
Autogenerate proxyclasses means basically that Doctrine 2 will automatically generate "proxy classes" for your entities, instead of only generating them manually using generate-proxies. Proxies are used when you have relations in your entities and they need to be lazy-loaded.
To generate mapping information from the database, you can use convert-mapping:
php doctrine orm:convert-mapping --from-database yml /path/to/mapping-path-converted-to-yml
Bear in mind that this is only recommended to be used as a starting point. The database driver is not able to correctly generate mappings for all possible combinations of options, so you probably should just run this once and then write mappings yourself.
See Doctrine 2 manual, "Reverse Engineering the database"
You can use the "annotation" as driver, if you want to get the generated entities:
php doctrine orm:convert-mapping --from-database annotation generatedModels

Zend 1.11 and Doctrine 2 Auto generate everything needed from already existing database

I am new to ORM and I am really keen to learn it. I successfully managed to install all classes and configurations for Doctrine 2.1 with Zend 1.11.x by following this tutorial.
http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/ Which uses Bisna plugin and doctrine scripts.
Now my problem is he is clearly explaining how to create entities and tables through doctrine classes but do not explain how to auto generate the proxies and repo classes from already existing database which helps me to select, insert and update. I always create my databases using MySQL Workbench.
I also followed the below tutorial as well
http://www.zend.com/en/webinar/Framework/70170000000bSrG-webinar-zf-v-1-doctrine-v-2-20101214.flv
My database is so complex with relationship flowing across every possible way. If I follow the steps which is explained in these tutorials I will never complete my project. Can any one please explain how to start using Doctrine after configuration. Considering I already have a database and my Model folders are empty. I have my folder sructure as below.
C:/zf/library/Doctrine
C:/zf/library/Symfony
C:/zf/library/ZC -- (my model which should contain the proxies and repo of Doctrine. At the moment it contains nothing.)
C:/zf/library/Zend
C:/zf/scripts/doctrine.php
Please help me!
I posted this same post yesterday and no one replied to my post. Please let me know if you need anymore information from me.
Thank you,
Karthik
According to Doctrine you should create your entities first yourself and then create your database schema from these entities.
But because you already have a database you probably don't want that. It is possible to convert your database to Doctrine2 entities in PHP, XML or Yaml.
You should take a closer look at the commandline tools Doctrine offers with the Bisna glue because there you can generate a lot of stuff.
To generate your entities FROM your database consider the following command:
php doctrine.php orm:convert-mapping --from-database php ../library/Application/Entity
You can also define the namespace and a base class which your entities have to extends with: --namespace=namespace and --extends=class.
Doctrine2 warns you to convert your database to entities because not everything could be auto detected or supported. For instance ENUM datatypes are not supported by default in Doctrine2 so converting your database will raise an error.
It's a good idea to check all your entities especially associations before you use them. Hope it helps you.
If I understand your question correctly, you have your entities already configured and need to auto-generate your proxy and repository classes.
Both can be created using the following Doctrine CLI commands from your application's root directory:
php scripts/doctrine.php orm:generate-proxies
php scripts/doctrine.php orm:generate-repositories library/
If you're looking for a way to auto-generate your entity classes, unfortunately I don't think a solution is available for this yet.
A support rep at ORM Designer said they are "working on" this feature and that it is "very demanded." Here's hoping it will be included in ORM Designer 2.0 since there is generally a lot of repetitive work involved in coding/mapping entity classes that could likely be automated.
You can use the orm:generate-entities command if you provide mapping information in either XML or YAML format.
See http://www.doctrine-project.org/docs/orm/2.1/en/reference/tools.html#entity-generation
For development, set proxy generation to be automatic in your config, otherwise, use the orm:generate-proxies command.
Unless you need to customise your repositories, generic ones are created in the entity manager when requested. To specify custom repositories, simply use the repository-class entity mapping attribute.
See http://www.doctrine-project.org/docs/orm/2.1/en/reference/xml-mapping.html#defining-an-entity for an example

Issues with doctrine build in Symfony

I am getting stuck with this Symfony command after following the Jobeet tutorial on their site. After running the build model command, here's what I get:
$ php symfony doctrine:build --model
doctrine generating model classes
file+ /private/var/folders/yX/yXtbVXwPHcCUpfC-n06OAU+++TI/-Tmp-/doctrine_schema_56533.yml
No yml schema found in /private/var/folders/yX/yXtbVXwPHcCUpfC-n06OAU+++TI/-Tmp-/doctrine_schema_56533.yml
Any ideas?
What's then full path to your schema.yml? Looks like it might be in the wrong place.
I encountered a couple of issues in the jobeet tutorial and found it helpful to compare my file contents/paths to the tag for the relevant day at http://svn.jobeet.org/doctrine/tags/
Did you make sure that all your schema code is YAML compliant?
Maybe you can share the content of your current schema.yml with us.

Categories