Symfony 4 make:entity {entity} generate in a custom directory in a multi doctrine connection
Asked Answered
S

2

6

New to symfony here

I have a two connection setup in my config/packages/doctrine.yaml.

Connection 1 is default; //connects to localhost:mysql:root:password:local_db
Connection 2 is remote; // connection to a server xxx.xxx.xx.xxx.:username:pwd:remote_db

Is it possible to generate an Entity class using the cli tool php bin/console make:entity Product to generate entity in a custom directory.

When I run the above command the "Product" enttity class gets generated in my src/Entity/ directory but I want it to be generated according to our needs,

so lets say in scenario 1 I want it to generate the Entity class in src/Entity/Customer/ directory and

in scenario 2 I want it to generate the Entity class in src/Entity/Products/ directory. If I am able to do this then, the migrations and entity mappings becomes a lot easier for me.

Sherrod answered 6/4, 2018 at 17:34 Comment(4)
What said —help ? Run it after command to See is there any optionPyridine
I do not understand why the downvotesSherrod
@Smaine the options I have for --help are regenerate, overwrite help, quiet, version, ansi, no-ansi, no-interaction, env,no-debugSherrod
Also useful to know: you can type only php bin/console make:entity and maker will ask you for the Entity name, then type first letters of the directory and tab, maker will autocomplete the directory.Segno
A
21

This works: bin/console make:entity Customer\\Cart:

created: src/Entity/Customer/Cart.php
created: src/Repository/Customer/CartRepository.php
Amylo answered 6/4, 2018 at 22:8 Comment(1)
FQCNs are also allowed: bin/console make:entity '\App\Custom\Entity\Customer\Cart', which can be helpful if you want to place your entities outside the default directory src/Entity.Dicentra
V
2

I would suggest using the FQCN (Fully Qualified Class Name) of the entity you wanna create, as follow:

bin/console make:entity '\App\Custom\Entity\Customer\Cart'
bin/console make:entity '\App\Custom\Entity\Products\Product'

This way you gonna be able to place your generated entities outside of the default directory: src/Entity

Viceroy answered 3/11, 2022 at 14:33 Comment(1)
Using '' around it causes an error in my case. Just the plain name space works. Thanks! ([ERROR] "App\Entity\'\App\Core\Entity\User'" is not valid as a PHP class name (it must start with a letter or underscore, followed by any number of letters, numbers, or underscores))Craniology

© 2022 - 2025 — McMap. All rights reserved.