PHP code example of xpat / crud-bundle

1. Go to this page and download the library: Download xpat/crud-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xpat / crud-bundle example snippets


// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new XPat\CrudBundle\XPatCrudBundle(),
        // ...
    );
}

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;
    }

    
}



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);
    }
}