11

I'm trying to generate entities for my Symfony 2application. The entities will be shared by several bundles (and maybe several applications), and thus I do not want them to belong to a bundle. I want them to be in the src/MyApp/Entity folder.

I already have the YML for my entities, stored in src/MyApp/Entity/config/doctrine (class1.orm.yml, ...)

I'm trying to generate the corresonding PHP classes using the doctrine:generate:entities task

Here is what I have in my app/config/config.yml

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: false
    mappings: 
      AppRest: 
        type: yml 
        prefix: AppRest\Entity 
        dir: %kernel.root_dir%/../src/AppRest/Entity/config/doctrine

Here is the command I use to generate the entities

php app/console doctrine:generate:entities AppRest/Entity

Here is the exception I get

[InvalidArgumentException]
Bundle "AppRest" does not exist or it is not enabled.

I want to make doctrine understand that I'm not trying to generate entities tha are in a bundle. I also tried specifying the --path option (--path=src/AppRest/Entity), but it did not change anything.

Can anyone help ?

Edit:

I removed the extra space in my dir, which solved the problem. The path option must be specified

David
  • 33,444
  • 11
  • 80
  • 118
  • 1
    I don't think you will have much luck with getting S2 to generate and use D2 entities outside of a bundle. Just put them in their own bundle and be done with it. It's easy to share entities across multiple bundles. – Cerad Apr 18 '12 at 17:55
  • +1 Using Sf2 coupled with Doctrine2 makes you to accept Doctrine implementation by Sf2... – AlterPHP Apr 19 '12 at 09:06

3 Answers3

4

Actually, I was just missing a space in my dir option above. This works now, but I'm still wondering whether that's the best way to go.

David
  • 33,444
  • 11
  • 80
  • 118
  • 3
    Bundle purpose is to integrate your PHP code with Symfony. The more code you move outside of a bundle, the less is Symfony dependent. – Jakub Zalas Apr 19 '12 at 11:50
  • Bundle is the best way to go. Try building some queries before you get too far along. You might run into some problems there. – Cerad Apr 19 '12 at 12:11
  • 1
    Yep, we've re-assessed that and we chose an implementation with a CoreBundle, which contains our Entities, and specialised bundles, which refer to that CoreBundle – David Apr 20 '12 at 06:37
1

Use:

is_bundle: false

More info here: http://zalas.eu/how-to-store-doctrine-entities-outside-of-a-symfony-bundle/

tomazahlin
  • 2,137
  • 1
  • 24
  • 29
-1

When you have such error, check if you specified the shortcut name of the bundle, not the name of the bundle directory. For example, if you have Acme\DemoBundle the shortname of it is AcmeDemoBundle. In this case

orm:
    mappings: 
      DemoBundle: 
          ....

is INCORRECT.

the correct is:

orm:
    mappings: 
      AcmeDemoBundle: 
          ....
pleerock
  • 18,322
  • 16
  • 103
  • 128