xpat / crud-bundle
Base controller for crud
Installs: 89
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4
- symfony/symfony: >=2.8
This package is not auto-updated.
Last update: 2025-01-03 08:53:19 UTC
README
Installation
Use Composer for the automated process:
composer require xpat/crud-bundle
Adding bundle to your application kernel
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new XPat\CrudBundle\XPatCrudBundle(), // ... ); }
Usage
Entity:
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Category * * @ORM\Table(name="category") * @ORM\Entity() */ class Category { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", nullable=false) */ private $name; /** * @return int */ public function getId() { return $this->id; } /** * @param int $id */ public function setId($id) { $this->id = $id; } /** * @return mixed */ public function getName() { return $this->name; } /** * @param mixed $name */ public function setName($name) { $this->name = $name; } }
Controller:
<?php namespace AppBundle\Controller; use AppBundle\Entity\Category; use AppBundle\Form\CategoryType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use XPat\CrudBundle\Classes\ListConfiguration; use XPat\CrudBundle\Controller\XPatCrudController; use XPat\CrudBundle\Service\CrudControllerParameters; /** * Class CategoryController * @package AppBundle\Controller * @Route("/category") */ class CategoryController extends XPatCrudController { /** * Entity class name * @return string */ protected function getEntity() { return Category::class; } /** * @param ListConfiguration $configuration */ protected function listConfiguration(ListConfiguration $configuration){ $configuration ->addField('id','id') ->addField("name","name"); } /** * @param CrudControllerParameters $parameters */ protected function configure(CrudControllerParameters $parameters) { $parameters->setTitle("Category"); $parameters->setFormType(CategoryType::class); } }