vincet/base-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Symfony VinceTBaseBundle

Installs: 1 297

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 3

Open Issues: 0

Type:symfony-bundle

4.1.2 2016-10-25 18:51 UTC

This package is auto-updated.

Last update: 2023-07-27 08:49:01 UTC


README

This bundle define base class to improve your development.

It requires SonataAdminBundle and SonataDoctrineORMAdminBundle

Installation

Use composer to install

composer require vincet/base-bundle

For symfony <2.5 use the 2.2 version

composer require vincet/base-bundle=2.2

Entity Management

This bundle defines a BaseManager class that is compatible with SonataAdmin ModelManager.

Juste define a new class for your entity :

namespace Acme\DemoBundle\Manager;

use VinceT\BaseBundle\Manager\BaseManager;

class PostManager extends BaseManager
{
}

Define the manager as a service in your services.yml :

parameters:
    post_manager.class: Acme\DemoBundle\Manager\PostManager

services:
    post_manager:
        class: %post_manager.class%
        arguments: [@service_container]

you can now acces this manager from any controller :

[...]
$postManager = $this->container->get('post_manager');
[...]
$post = new Acme\DemoBundle\Entity\Post();
[...]
$postManager->create($post);
[...]
$postManager->update($post);
[...]
$postManager->delete($post);
[...]

To use this manager with SonataAdmin, add a call to setModelManager in your services.yml file

services:
    acme.demo.admin.post:
      class: Acme\DemoBundle\Admin\PostAdmin
      tags:
        - { name: sonata.admin, manager_type: orm, group: Blog, label: Post }
      arguments: [null, Acme\DemoBundle\Entity\Post, AcmeDemoBundle:PostAdmin]
      calls:
        - [ setModelManager, [ @page_manager ] ]
        - [ setTranslationDomain, [ AcmeDemoBundle ] ]

Your front and Admin application will now use the same entity manager.

Admin Controller

This bundle also define a BaseAdminController that catch exception throwed during an admin action. It is very easy to use :

Define your admin controller :

namespace Acmd\DemoBundle\Controller;

use VinceT\BaseBundle\Controller\BaseAdminController;

class PostAdminController extends BaseAdminController
{
}

Don't forget to use this controller in your admin service (the third argument).

services:
    acme.demo.admin.post:
      class: Acme\DemoBundle\Admin\PostAdmin
      tags:
        - { name: sonata.admin, manager_type: orm, group: Blog, label: Post }
      arguments: [null, Acme\DemoBundle\Entity\Post, AcmeDemoBundle:PostAdmin]

Commands

To make your development faster a command can generate the following classes for an entity, bundle or namespace :

  • Admin/EntityAdmin
  • Controller/Admin/EntityAdminController
  • Manager/EntityManager

and create/update the following files :

  • Resources/config/services.yml
  • Resources/translations/YourBundle.en.yml
  • Resources/translations/YourBundle.fr.yml

To use it :

php app/console vincet:generate MyBundle:Post

Another command generate a frontend CRUD controller. It's based on the \Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand

To use it :

php app/console vincet:generate:crud