nedra / rest-bundle
基于您的实体生成REST API
1.3.9
2017-09-29 14:13 UTC
Requires
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- friendsofsymfony/rest-bundle: ^2.1
- gedmo/doctrine-extensions: ^2.3.1
- jms/serializer-bundle: ^1.1
- symfony-cmf/routing-bundle: ^2.0
- symfony/dependency-injection: ^3.3
- symfony/framework-bundle: ^3.3
- symfony/http-kernel: ^3.3
- symfony/routing: ^3.3
- symfony/twig-bundle: ^3.3
- symfony/yaml: ^3.3
Requires (Dev)
- phpunit/phpunit: ^5.7
- satooshi/php-coveralls: ^1.0
- symfony/symfony: ^2.8|^3.3
README
NedraRestBundle
NedraRestBundle 可根据您的模型自动创建REST API。只需提供您的模型并使用自动生成的端点。
入门指南
Bundle在基于Doctrine ORM的模型上运行。Bundle的目的是以最快、最简单的方式生成REST API。
安装
步骤 1: 更新composer.json
composer require nedra/rest-bundle
步骤 2: 在AppKernel
中注册类
[...] new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle($this), new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(), new Nedra\RestBundle\NedraRestBundle(),
步骤 3: 更新config.yml
以配置NedraRestBundle
nedra_rest: active: true # this is default value, you can disable the bundle with set to false entities: app.model: classes: model: AppBundle\Entity\Model
注意
app.model
是一个模式示例。您必须使用应用前缀(如app
)定义您的模型
检查路由
运行该命令并调试您的路由器
bin/console debug:router
您将看到自动生成的REST路由
app_model_index GET ANY ANY /models/ app_model_create POST ANY ANY /models/new app_model_update PUT|PATCH ANY ANY /models/{id} app_model_show GET ANY ANY /models/{id} app_model_delete DELETE ANY ANY /models/{id}
配置参考
nedra_rest: entities: app.model: path: model # you can change /models/ to /cars/ except: ['show'] only: ['create', 'index'] classes: model: AppBundle\Entity\Model form: AppBundle\Form\ModelType
注意
您只能使用其中的一个:`except`或`only`