Skip to content

CRUD generator? #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabpot opened this issue Nov 10, 2017 · 29 comments
Closed

CRUD generator? #3

fabpot opened this issue Nov 10, 2017 · 29 comments
Labels
Feature New Feature

Comments

@fabpot
Copy link
Member

fabpot commented Nov 10, 2017

This bundle actually does not replace the current generator bundle as it was more focused on a CRUD generator. Is it something we want to do here as well?

@weaverryan
Copy link
Member

Maybe. The old generator - at least after years of existing - generated some ugly code. Obviously... we shouldn’t let that happen again.

But... i guess it is a nice thing to have. We could wait for people to ask for it... but if we know they’ll want it, why wait.

@mneuhaus
Copy link

yes please :) 😃

@MarioBlazek
Copy link

MarioBlazek commented Nov 20, 2017

It would be a nice feature to have 👍

@ad3n
Copy link

ad3n commented Nov 23, 2017

Yes we need but with more clearly... Sensio Generator is ugly, redundant and repeated code anywhere

@ogizanagi
Copy link

How is the old CRUD generator used nowadays? I mean, isn't an admin CRUD generator like EasyAdmin more efficient & simpler? Or is it really used to bootstrap code in an application?
For my part, I never used the old CRUD generator.

@dsentker
Copy link

The crud Generator is used often in my projects. I would really love a modern crud Generator here.
Btw i do not think that the sensio generator bundle creates 'ugly' Code.
+1 for a modern crud Generator 👌

@Leuloch
Copy link

Leuloch commented Nov 26, 2017

I'm about to start a new project with symfony 4, and waiting for the CRUD generator feature! I'm a freelancer and this would help me a lot to bootstrap apps

@codedmonkey
Copy link
Contributor

codedmonkey commented Nov 29, 2017

I like the idea of a CRUD generator, the old one provides enough basic utility for a functional starting point. When looking at the generated code, the PHP-code is just a basic Symfony controller, which seems fine. The templates, on the other side, are something to be more opinionated about. Obviously it would be unwise to include CSS with the generated code as it would increase complexity for the user.

One solution to this could be a mechanic where third-party bundles are allowed to override the skeleton files (#33). A dedicated bundle (like a Bootstrap bundle) would be able to provide more modern templates. The Bootstrap example is just one of the use cases, an official bundle would be unlikely to make everybody happy on this.

@lemorragia
Copy link

yesss!!

@inmarelibero
Copy link

I consider this an extremely important feature to have; "old" generator bundle does not provide ugly code, but it has come issue I personally handle very time I use it:

  • can't choose in what folder generate the controller, form and templates
  • different new.html.twig and edit.html.twig templates: first things I do is delete one of them and use the other for both newAction() and editAction
  • rename variables in generated controller: 'edit_form' => form, $editForm => $form
  • remove delete form from edit template
  • use uuid instead of id

so +1 for a new generator, hopefully extendable giving the possibility to the user to choose options above

@ksn135
Copy link

ksn135 commented Dec 2, 2017

👍 for CRUD

@kironet
Copy link

kironet commented Dec 3, 2017

That would be great to have all important commands in one bundle. 👍

@lyrixx
Copy link
Member

lyrixx commented Dec 4, 2017

My 2 cents: If you need a basic CRUD generator, why don't you use EasyAdminBudle? It's so simple to set-up and to configure.

So for me, except for a training session, the CRUD generator is useless.

Anyway, This should be quite easy to develop it, But only if we support 0 options (we should only support Doctrine + Twig + no pagination + no filtering)

@javiereguiluz
Copy link
Member

When someone mentions "CRUD generator", we think about the old symfony 1 admin generator or SonataAdmin, etc. But we can't make that because:

  • If we make complex templates (the ones you need in a real app) then we'll complicate the MakerBundle a lot and we're repeating the work done by third-party bundles;
  • If we make simplistic templates (like the ones generated by SensioGenerator) then that's useless in a real app: you don't even get pagination for listings!!

However, we could forget about the templates and other resources and only generate the controller part. This could be similar to the Rails routing resources. For example, if you put resources :photos in the Rails routing file ... you get a full controller to manage photos:

rails-resources

See http://guides.rubyonrails.org/routing.html for details.

@fabpot
Copy link
Member Author

fabpot commented Dec 4, 2017

CRUD != admin generator. There is nothing in common between the 2. A CRUD generator is something that give you some code for you to modify. You own the code. And admin gen is something that let's you configure some generic code that you don't own.

We do have admin gens, and SensioGeneratorBundle is a CRUD generator. The latter is what we should replace.

@mneuhaus
Copy link

mneuhaus commented Dec 4, 2017

another approach to reduce the CRUD boilerplate could be something similar to Djangos Class Based Views.
Has something like this been considered before to reduce some boilerplate?

@ksn135
Copy link

ksn135 commented Dec 4, 2017

In the past:
sf 1.x – built-in admingenerator
sf 2-3 – symfony2admingenerator/GeneratorBundle based on "deprecated" SensioGeneratorBundle
@fabpot What should I do NOW to build and maintain enterprise system with many DB tables with Symfony 4 ? Is there some receipt for Flex to generate complex templates and code (mean option 1 from @javiereguiluz 's comment) ?

@fabpot
Copy link
Member Author

fabpot commented Dec 4, 2017

@ksn135 Not sure I understand your comment here. In Symfony 4, you have several admin generators... which are different from CRUD generation (see my previous comment).

@chepeftw
Copy link

chepeftw commented Dec 4, 2017

I vote in favor of CRUD 😁
I think that the CRUD functionality is somehow important, first of all, it provides a solid ground for new devs for Symfony because it does not matter how explained you have something in the docs, if there are not meaningful examples then not everybody will fully understand what they are reading, but examples work most of the time and CRUD provides an easy way of devs generating their own skeletons as examples and from there pivot to more advanced stuff.
Second, one thing is admin generator bundle and one thing is to generate a basic HTML to start coding specific functionality. As @fabpot explained before. For experienced devs I think is useful since it saves you some time, some might argue that its "ugly" HTML but you can customize it by overriding the existing "ugly" HTML, others might argue that you could do it yourself, but once again it saves time, it provides an easy way to generate a good skeleton and then focus on what really matters.

@codedmonkey
Copy link
Contributor

It sounds like this is the first thing people are missing when experimenting with Symfony 4. I think that in addition to @fabpot's argument, it's important to point out that we're trying to make it as easy as possible to create your own makers. Anybody who wants to customize the output for the CRUD generator is free to do so and could even publish it as a bundle. Built-in makers should remain as simple as possible.

@gonzaloalonsod
Copy link

The idea is to have a single controller, views, etc., from which the generated code extends.
For example:
https://github.com/MWSimple/AdminCrudBundle

@mreichstadt
Copy link

Hi everybody,
I vote YES!!!! for this because:

  • generator creates templates (ok ugly but at least files are created)
  • generator creates all the methods (add, edit, show, delete)
  • generator creates the forms

In some of my apps, I have around 100 tables, and it's very useful for me to generate the crud for all my tables and then juste customize the twig part. Without that option, it would increase the time needed to develop it.

Other thing that is not linked, is it possible to add fields to an entity without having to get through the PHP file as we used to do in sf3 with command line?

@Gonzalo1987
Copy link

Gonzalo1987 commented Jan 24, 2018

I'd love to have a templates generator like generate:doctrine:crud... and I'd love that make:entity works like generate:doctrine:entity and request the entity's fields and generate the annotations for that entity...

I feel that in S4 I need write more code than in the previous versions.

Greetings!

@dsentker
Copy link

@fabpot , most of us may have realized that a CRUD generator is not an admin generator. Regardless, I'm assuming that a CRUD entity generator will make life easier for many developers. Are there concrete plans to integrate something like this?

@javiereguiluz
Copy link
Member

We are going to add an entity generator and we are probably going to add a CRUD generator like in the old SensioGeneratorBundle. When? No estimate date. We don't have enough resources to do all the things we want to do.

@mreichstadt
Copy link

It's possible and easy to create your own crud generator, as I did for some of my projects. This is not a "bundle" but a small set of programs I launch like this: php bin/createForm. For the moment it generates all the CRUD with either a very simple template (like it was done before) or a self-made template we use in our company.

@sadikoff
Copy link
Contributor

Hi all.

Need your advise. I have working crud generator as extension to maker-bundle, but for now generated code is not very beautiful. I can continue working on the bundle, if it is needed. But I don't know what is the best solution for generated code.

@javiereguiluz javiereguiluz added the Feature New Feature label Jan 24, 2018
@weaverryan
Copy link
Member

@sadikoff the best solution might be to apply your code directly to this bundle and create a PR for the CRUD generation :). If you want to put in some work to build this command, we can help you and it will get done much faster.

@sadikoff
Copy link
Contributor

@weaverryan thx I'll prepare PR for this feature tomorrow.

weaverryan added a commit that referenced this issue Mar 14, 2018
…averryan)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Add make:crud & improve make:form commands

Hi all,

## Improved make:form command
Main improvement is that command works in two ways. First way simple, it just generates skeleton form class and user can do with it whatever he want. Second way is generation from entity class. Generator checks if entity exists and ask user if he wants to generate form from entity or user can use `--entity` flag if he knows that entity exists.
### Generation features:
- Simple skeleton form class
- Doctrine entity form class
### Examples:
**Simple class generation**
```bash
root@striX: ~/project_root# bin/console make:form

 The name of the form class (e.g. GentleElephantType):
 > SimpleForm

Enter the class or entity name that the new form will be bound to (empty for none):
 >

 created: src/Form/SimpleFormType.php

  Success!
```
**Entity form generation**
```bash
root@striX: ~/project_root# bin/console make:form

 The name of the form class (e.g. GentleElephantType):
 > EntityFormType

Enter the class or entity name that the new form will be bound to (empty for none):
 > Entity

 created: src/Form/EntityFormType.php

  Success!
```
Closes: #114

## New make:crud command
Want to introduce `make:crud` command it is similar to doctrine:generate:crud from SensioGeneratorBundle.

All you need to generate cool crud is Entity :)
### Features
- complete crud generation
### Example:
```bash
root@striX: ~/project_root# bin/console make:crud SweetFood

 created: src/Controller/SweetFoodController.php
 created: src/Form/SweetFoodType.php
 created: templates/sweet_food/_delete_form.html.twig
 created: templates/sweet_food/_form.html.twig
 created: templates/sweet_food/index.html.twig
 created: templates/sweet_food/show.html.twig
 created: templates/sweet_food/new.html.twig
 created: templates/sweet_food/edit.html.twig

  Success!

```
Closes: #3

Commits
-------

2683114 some improvements
2ec8ff0 fix form variables
0d9e637 added validation on arguments
ada7db0 fix phpcs
f740e2e fix variables to follow official recommendations
b3bf878 some make:form improvements + experiments
204f5aa final fix for skeleton templates
96d54a7 Merge branch 'master' of https://github.com/sadikoff/maker-bundle
38b2864 Merge remote-tracking branch 'upstream/master'
ee98865 making test name less specific so we can run only it
ba0438f phpcs fix
3d319bd some skeleton improvements
da37780 Merge remote-tracking branch 'upstream/master'
2ebff8c fix cs and improvements according to review request
772f0db fix make:form
44b7851 completed improvement of make:form command
db30634 added tests for crud testig
ad8a4fb fix tests on appveyor
e8eabd6 Merge remote-tracking branch 'upstream/master'
60c0005 php cs fix
404c38f update all to lastest bundle code
cc4b758 Merge remote-tracking branch 'upstream/master'
1b95509 add csrf dependency it's necessary for delete action in crud and for better security
52a20bb improve make:crud command to use make:form logic for form generation
e24b22c fix to use with php 7.0
7555a3a improved make:form command
4045695 removed unnecessary code
7ed6b8b improved tests
3787739 cs fix
71d2e90 some code refactoring + testing new GeneratorHelper to simplify skeleton templates
6f1c296 array style fix
96f2af2 Merge remote-tracking branch 'upstream/master'
ab0a0dc Merge remote-tracking branch 'upstream/master'
422d31b Merge branch 'master' of https://github.com/sadikoff/maker-bundle
ff9a08d some fixes
42047a6 fix Token parameter name in delete action
5157e0a fix interception of /new url by show action
7783313 fix fobpot.io cs
31d9e81 fix templates generation with date fields in entity
1b0f17a test remove some phpdoc comments to pass travis.ci
207d8be add exception if entity doesn't exists
478b457 fix fabpot.io cs 3
791241d fix fabpot.io cs 2
9961f43 fix fabpot.io cs
f189efd fix tests
8c98b45 trying tests 2
08d4bc5 trying tests
8e9bd67 fix skeleton according to community recommendations
e9f91ef add MakeCrud class to makers.xml
6cdda8f final fix fabpot.ci CS
4c0b639 fix fabpot.ci CS
bf9a5c1 make:crud command initial commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature
Projects
None yet
Development

No branches or pull requests