javihgil / utils-bundle
This package is abandoned and no longer maintained.
The author suggests using the javihgil/extra-bundle package instead.
v1.0.1
2015-09-27 14:35 UTC
Requires
- doctrine/orm: ~2.2,>=2.2.3
- symfony/config: ~2.3
- symfony/dependency-injection: ~2.3
- symfony/form: ~2.3
- symfony/http-foundation: ~2.3
- symfony/http-kernel: ~2.3
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.2.*
This package is auto-updated.
Last update: 2019-02-20 19:42:20 UTC
README
Utility classes for Symfony projects
Installation
composer require 'javihgil/utils-bundle'
Configure Bundle
Register the bundle in app/AppKernel.php:
// app/AppKernel.php
public function registerBundles()
{
return [
// ...
new \Jhg\UtilsBundle\UtilsBundle(),
];
}
Create form handler
Handler for creating doctrine entities in a CRUD controller.
Example
/**
* @param Request $request
*
* @return Response
*/
public function createAction(Request $request)
{
$element = new Element();
$form = $this->createForm(new ElementType(), $element);
if ($this->get('create_form_handler')->process($form, $request)) {
return $this->redirectToRoute('success_route', ['element', $element->getId()]);
}
$viewData = [
'form' => $form->createView(),
];
return $this->render('ExampleBundle:Element:create.html.twig', $viewData);
}
Update form handler
Handler for updating doctrine entities in a CRUD controller.
Example
/**
* @param Element $element
* @param Request $request
*
* @return Response
*/
public function updateAction(Element $element, Request $request)
{
$form = $this->createForm(new ElementType(), $element);
if ($this->get('update_form_handler')->process($form, $request)) {
return $this->redirectToRoute('success_route', ['element', $element->getId()]);
}
$viewData = [
'element' => $element,
'form' => $form->createView(),
];
return $this->render('ExampleBundle:Element:update.html.twig', $viewData);
}
Delete form handler
Handler for deleting doctrine entities in a CRUD controller.
Example
/**
* @param Element $element
* @param Request $request
*
* @return Response
*/
public function deleteAction(Element $element, Request $request)
{
$form = $this->createForm(new ElementType(), $element);
if ($this->get('delete_form_handler')->process($form, $request)) {
return $this->redirectToRoute('success_route');
}
$viewData = [
'element' => $element,
'form' => $form->createView(),
];
return $this->render('ExampleBundle:Element:delete.html.twig', $viewData);
}