dev-master
9999999-dev https://github.com/eduardoledo/GenericAdminBundleA generic, easy to use CRUD generator for Symfony2
Unlicense
The Requires
by Eduardo Ledo
symfony2 crud admin
A generic, easy to use CRUD generator for Symfony2
A generic, easy to use CRUD generator for Symfony2, (*1)
This version of the bundle requires FOSUserBundle, Makerlabs PagerBundle and StfalconTinymceBundle. Both packages are installed automatically if not found., (*2)
Installation is a quick 3 steps process:, (*3)
Add GenericAdminBundle in your composer.json:, (*4)
{ "require": { "eduardoledo/generic-admin-bundle": "*" } }
Now tell composer to download the bundle by running the command:, (*5)
``` bash $ php composer.phar update eduardoledo/generic-admin-bundle, (*6)
Composer will install the bundle to your project's `vendor/eduardoledo` directory. ### Step 2: Enable the bundle Enable the bundle in the kernel: ``` php <?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:, (*7)
``` php <?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(), ); }, (*8)
**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 <?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 }
You have to add a section for each entity in config.yml
:
``` yaml, (*9)
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, (*10)
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 be `acme_demo_users_index` and the route_prefix would be `acme_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: ``` yml # app/config/routing.yml lomaswifi_admin: resource: "@LomaswifiAdminBundle/Controller/" type: annotation prefix: /
If everything went as planned you can now test the GenericBundleAdmin at http://your_server_url/admin
., (*11)
Enjoy, (*12)
A generic, easy to use CRUD generator for Symfony2
Unlicense
symfony2 crud admin