arkounay/quick-admin-generator-bundle

QAG is a bundle that generates cruds admin for Symfony applications using Doctrine.

5.4.4 2024-03-21 14:59 UTC

README

GitHub release (latest SemVer) GitHub Workflow Status MIT License codecov

QAG is a bundle that allows quick and simple generation of administration backends for Symfony applications using Doctrine.

Quick Admin Generator Preview

Getting started

Install the dependency:

composer require arkounay/quick-admin-generator-bundle

also, make sure the following line was added in config/bundles.php:

Arkounay\Bundle\QuickAdminGeneratorBundle\ArkounayQuickAdminGeneratorBundle::class => ['all' => true],

and that assets were installed: php bin/console assets:install --symlink.

Finally, add the following route configuration, for example in config/routes.yaml:

qag_routes:
    resource: 'Arkounay\Bundle\QuickAdminGeneratorBundle\Crud\RouteLoader'
    type: service
    prefix: '/admin'

You will probably want to secure the /admin route prefix. To do so, you can add the following line in your security.yaml:

access_control:
     - { path: ^/admin, roles: ROLE_ADMIN }

and that's it, the bundle is ready to be used.

Now, you can add a Controller that extends Arkounay\Bundle\QuickAdminGeneratorBundle\Controller\Crud to add your first crud.

For example, let's say you have a News entity.

!> Make sure your entity implements __toString()!

Create a controller, for instance src/Controller/Admin/NewsController.php, with the following code:

namespace App\Controller\Admin;

use App\Entity\News;
use Arkounay\Bundle\QuickAdminGeneratorBundle\Controller\Crud;

class NewsController extends Crud
{
    public function getEntity(): string
    {
        return News::class;
    }
}

and now refresh /admin in your browser. You should see a new "News" item that appeared in the menu, and you should now be able to create, edit, and delete news.

If you use the symfony command to display routes php bin/console debug:router, you'll see that some routes have been generated for you:

qag.category                       ANY      ANY      ANY    /admin/category/                  
qag.category_create                ANY      ANY      ANY    /admin/category/create            
qag.category_delete                ANY      ANY      ANY    /admin/category/delete/{id}/      
qag.category_delete_batch          ANY      ANY      ANY    /admin/category/deleteBatch      
qag.category_edit                  ANY      ANY      ANY    /admin/category/edit/{id}/        
qag.category_export                ANY      ANY      ANY    /admin/category/export
qag.category_filter_form_ajax      ANY      ANY      ANY    /admin/category/filterFormAjax
qag.category_toggle_boolean_post   POST     ANY      ANY    /admin/category/toggleBooleanPost/{id}/

Next steps

There are multiple ways to configure and override things in QAG Bundle, depending on the complexity of the project. You can use attributes for simple and quick tweaks regarding entity fields, override Twig templates to change the appearance, add listeners to create special rules that apply when parsing entities, and more.

See :

  1. Fields configuration
  2. Controllers, lists, and security
  3. Actions and routing
  4. Forms
  5. Configuring menu items and their position
  6. Overriding the rest of the twigs