bryanhenry/metrify-bundle

使用Symfony、FOSRestBundle和Doctrine2的快速CRUD便捷工具

安装: 12

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.x-dev 2017-06-19 21:26 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:43:06 UTC


README

使用Symfony、FOSRestBundle和Doctrine简化CRUD操作。

摘要

此包旨在减少使用FOSRestBundle和Symfony表单进行简单CRUD时的样板代码,但不适用于复杂交互。

用法

创建您的实体,并实现FormEntityInterface接口

namespace MyNameSpace;

class MyEntity extends FormEntityInterface {

	protected $id;

	public function getId() : ?int
	{

	    return $this->id;

	}

}

创建您的控制器,并扩展AbstractCrudController抽象类。

namespace MyNameSpace;

use BryanHenry\MetrifyBundle\Components\Controller\AbstractCrudController;
use MyNameSpace\MyEntity;
use MyNameSpace\MyEntityFormType;

/**
 * Set your prefix here, or through yml.
 * @RouteResource("item/definitions")
 */
class MyControllerController extends AbstractCrudController
{

    // Return the name of the form class here.
    protected function getFormName(): string
    {
        return MyEntityFormType::class;

    }

    // Return the name of the entity here, ensure that it implements the FormEntityInterface interface.
    protected function getEntityName(): string
    {
        return MyEntity::class;
    }

}

在您的实体仓库类内部,您必须使用提供的特性行提供分页

namespace MyNameSpace;

use Doctrine\ORM\EntityRepository;
use BryanHenry\MetrifyBundle\Components\Repository\RepositoryPaginateTrait;

class MyEntityRepository extends EntityRepository
{

    use RepositoryPaginateTrait;

}

贡献者

Bryan Henry bryan@misterflow.com

许可证

MIT