Peter
Peter

Reputation: 9123

How to generate entities and cruds in SF4?

I've just installed symfony 4 and after noticing the structure being slightly different, searching for some config files and editing around a bit, I was planning to go and generate my first entities and cruds.

However, I found that symfony 4 does no longer support the doctrine:generate:entity command.

Instead I found that symfony now offers the MakerBundle that comes with a range of simple commands to generate the most basic code snippets.

What I am wondering is if there is still a way to interactively generate an entity and/or crud.

I tried installing the SensioGeneratorBundle but that doesn't yet seem compatible with symfony 4.

Upvotes: 0

Views: 682

Answers (3)

Dmitry S.
Dmitry S.

Reputation: 4534

Use MakerBundle:

composer req doctrine maker

For example, create your entity:

php bin/console make:entity Product

If you want use annotations, run:

composer req annotations

...then you need this informations:

Examples the commands for to works with entities (database)

Symfony use Doctrine.

If your don't have database, run this command:

php bin/console doctrine:database:create

If you want create entities in your database:

php bin/console doctrine:schema:create

If your need update your entities, run this command:

php bin/console doctrine:schema:update --force

For help, run command:

php bin/console list doctrine

So, your can generate entities if you already have database, see list doctrine.

Upvotes: 1

Mat
Mat

Reputation: 1007

What I am wondering is if there is still a way to interactively generate an entity and/or crud.

Why not use maker, which you mentioned?

 composer require maker --dev

Then, run:

bin/console make:entity

Upvotes: 1

delboy1978uk
delboy1978uk

Reputation: 12375

Create a plain old PHP object, add some doctrine annotations to it for the properties which are columns, then do a doctrine:migrations:diff. A migration file will be created with the SQL required. Then you run doctrine:migrations:migrate and the SQL will be executed.

Upvotes: 1

Related Questions