xpat/crud-bundle

CRUD 的基础控制器

安装: 88

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2018-01-29 08:40 UTC

This package is not auto-updated.

Last update: 2024-09-27 07:38:16 UTC


README

安装

使用 Composer 进行自动化处理

 composer require xpat/crud-bundle

将包添加到应用程序内核

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

    
}

控制器

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