GenericAdminBundle
A generic, easy to use CRUD generator for Symfony2
Prerequisites
This version of the bundle requires FOSUserBundle, Makerlabs PagerBundle and StfalconTinymceBundle. Both packages are installed automatically if not found.
Installation
Installation is a quick 3 steps process:
- Download GenericAdminBundle using composer
- Enable the bundle
- Create your controller class
- Configure the GenericAdminBundle
- Import the GenericAdminBundle routing
Step 1: Download FOSUserBundle using composer
Add GenericAdminBundle in your composer.json:
{
"require": {
"eduardoledo/generic-admin-bundle": "*"
}
}
Now tell composer to download the bundle by running the command:
$ php composer.phar update eduardoledo/generic-admin-bundle
Composer will install the bundle to your project's vendor/eduardoledo
directory.
Step 2: Enable the bundle
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Lomaswifi\AdminBundle\LomaswifiAdminBundle(),
);
}
If you did'n previusly installed FOSUserBundle, Makerlabs/PagerBundle or StfalconTinymceBundle you also have to enable them in the kernel which would look something like this:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new FOS\UserBundle\FOSUserBundle(),
new MakerLabs\PagerBundle\MakerLabsPagerBundle(),
new Stfalcon\Bundle\TinymceBundle\StfalconTinymceBundle(),
new Lomaswifi\AdminBundle\LomaswifiAdminBundle(),
);
}
Note: FOSUserBundle and Makerlabs/PagerBundle MUST be loaded BEFORE GenericAdminBundle
Step 3: Create your Controller class
In order to have all the corresponding routes and actions, you need to create a controller class for each entity that you want to have a CRUD, extending \Lomaswifi\AdminBundle\Entity\myController
or a subclass:
<?php
namespace Acme\DemoBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Route("/admin/users")
*/
class UsersController extends \Lomaswifi\AdminBundle\Entity\myController
{
protected $section = 'user'; // The section name you used in the config.yml
}
Step 4: Configure the GenericAdminBundle
You have to add a section for each entity in config.yml
:
# app/config/config.yml
lomaswifi_admin:
sections:
user:
title: Users # Title shown in CRUD
singular: user
plural: users
route_prefix: acme_demo_users # Route prefix
entity: AcmeDemoBundle:User # Entity alias
form_class: \Lomaswifi\BlogBundle\Form\PostType
form_service: fos_user.registration.form
fields:
username:
name: username
label: username
email:
name: email
label: Email
For each entity you have to create a section with the following parameters:
- Title: the section title.
- singular: the singular name of the entity
- plural: the plural name of the entity
- route_prefix: the prefix of the routes for the controller, as generated by symfony for routes without explicit name, based on namespace. In this example the route prefix for
Acme\DemoBundle\Controller\UsersController::indexAction
would beacme_demo_users_index
and the route_prefix would beacme_demo_users
- entity: the entity alias
- form_class/form_service: the form fully qualified classname or form service for the entity
- fields: an array with the names and labels of the fields you wish to display in the CRUD listing
Step 5: Import the GenericAdminBundle routing
Last but not least, we add the basic routes for the admin to function:
# app/config/routing.yml
lomaswifi_admin:
resource: "@LomaswifiAdminBundle/Controller/"
type: annotation
prefix: /
Next step
If everything went as planned you can now test the GenericBundleAdmin at http://your_server_url/admin
.
Enjoy