Git Product home page Git Product logo

basebundle's Introduction

BaseBundle

This bundle define base class to improve your development.

It requires SonataAdminBundle and SonataDoctrineORMAdminBundle

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

basebundle's People

Contributors

seldaek avatar vincenttouzet avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.