tpg/extjs-bundle
最新稳定版本:v2.3.3
Composer 安装命令:
composer require tpg/extjs-bundle
包简介
Use ExtJs with Symfony 2
README 文档
README
Use ExtJs with Symfony 2
Packagist: https://packagist.org/packages/amstaffix/extjs-bundle
The aim of this bundle is to ease the intergration between Symfony 2 and ExtJS client side framework. It support
- Dynamic runtime generation of Ext.data.Model based on entities/models implement on the server side.
- Auto integrate of Ext Remoting integration with Symfony 2 Controller.
- Code generation of Rest Controller per entities, support GET, POST, PUT, PATCH and DELETE.
Requirement
Mandatory
- Symfony ~2.3
- Serializer library from JMS ~1.0
- Doctrine ORM or ODM
- Generator from Sensio ~2.3
Optional
- Rest Controller code generator need FOSRestBundle ~1.0
Installation
Using composer
$ composer require amstaffix/extjs-bundle
Enabling bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new JMS\SerializerBundle\JMSSerializerBundle(), new \Tpg\ExtjsBundle\TpgExtjsBundle(), ); }
Add routing rules
# app/config/routing.yml tpg_extjs: resource: "@TpgExtjsBundle/Resources/config/routing.yml" prefix: /extjs
All documentation below, we assume all ExtJs controller path is prefix with /extjs.
Configuration
tpg_extjs: entities: - @AcmeDemoBundle/Entity/ - @AcmeDemoBundle/Model/Auto remoting: bundles: - AcmeDemoBundle
Testing Run
Unit Test are written with PHPUnit and Jasmine JS. How to run unit test is in .travis.yml file.
Model/Entities Code Generation
You may need to configure the additional routing rule for this feature to work. To generate Ext.data.Model code, you just need to include script tag pointing to generateModel.js
To generate all entities and document configured in the configuration,
<script type="text/javascript" src="/extjs/generateModel.js"></script>
To generate some specific entities,
<script type="text/javascript" src="/extjs/generateModel.js?model[]=Acme.DemoBundle.Entity.Person&model[]=Test.TestBundle.Model.Book"></script>
Acme.DemoBundle.Entity.Person and Test.TestBundle.Model.Book is the full namespace of the model, just replace slash () with dot (.).
The entity class must annotate with Tpg\ExtjsBundle\Annotation\Model, please check out Tpg/ExtjsBundle/Tests/Fixtures/Test/TestBundle/Model/*.php for example usage.
There is a Twig extension (extjs_model) to make it easy to include/load model onto/from the current page.
To generate and inject the ExtJS code onto the current page,
{{ extjs_model(true, 'Acme.DemoBundle.Entity.Person', 'Test.TestBundle.Model.Book') }}
To reference and load ExtJS code through script tag,
{{ extjs_model(false, 'Acme.DemoBundle.Entity.Person', 'Test.TestBundle.Model.Book') }}
Remoting integration
You will need to configure remoting parameter to get ExtJs Remoting working with Controller.
To generate the glue for the remoting intergation on the page, just include
<script type="text/javascript" src="/extjs/remoteapi.js"></script>
To enable a controller's action remotable, you need to annotate the function with Tpg\ExtjsBundle\Annotation\Direct.
If controller parameter is expecting Symfony\Component\HttpFoundation\Request object then you need to call the remote api with only 1 parameters. You need to wrap parameters in array.
public function testRequestParamAction(Symfony\Component\HttpFoundation\Request $request) { $idResult = $request->query->get("id"); $nameResult = $request->query->get("name"); }
$idResult will contain 12 and $nameResult will contain "EFG".
To call that remote api, you need to use.
Test.testRequestParam({"id":12, "name":"EFG"});
Code generation of Rest Controller
The rest controller code generation is an extension of Sensio's controller generator. The generated controller will extend FOS\RestBundle\Controller\FOSRestController class.
You will need to enable the following bundles.
new \JMS\SerializerBundle\JMSSerializerBundle(), new \FOS\RestBundle\FOSRestBundle(),
You also need to make sure the following configuration for fos_rest.
fos_rest: service: serializer: tpg_extjs.serializer routing_loader: default_format: json param_fetcher_listener: true
Generated controller set different groups on JMS serializer context during serialization and deserialization process.
- get: Serialization on individual entity during GET, POST, PUT, PATCH action.
- list: Serialization on list of entity during GET action.
- post: Deserialization on individual entity during POST action.
- put: Deserialization on individual entity during PUT action.
- patch: Deserialization on individual entity during PATCH action.
For example,
To generate a rest controller (PeopleController) for entity Acme.DemoBundle.Entity.Person,
php app/console generate:rest:controller --controller AcmeDemoBundle:People --entity AcmeDemoBundle:Person
Attributes in entity need to be have JMS type specify for deserializing to work.
Only controller and entity option is require, all the rest of the option can be left as default. The generator will create/update 2 files,
- Acme\DemoBundle\Controller\PeopleControler will be generated.
- Acme\DemoBundle\Resources\config\routing.rest.yml will be updated or created
To include this generated rest controller into the routing table, just include
# app/config/routing.yml acmedemo_api_rest: resource: "@AcemeDemoBundle/Resources/config/routing.rest.yml" prefix: /api type: rest
PHP 5.4 Trait Support Using generate:rest:controller with --trait option the generator will generate 2 class for you,
- Trait Controller Class
- Actual Controller Class
Seperating the generated code and the your custom implementation on the controller. This will allow you to regenerate the controller without affecting your custom implementation.
Connecting ExtJS Rest Proxy with Rest Controller in Symfony
To specify rest proxy in extjs model, you need
// in file Acme\TestBundle\Entity\Car.php /** * @Extjs\Model * @Extjs\ModelProxy("/api/cars") * @ORM\Entity * @ORM\Table(name="car") */ class Car { ...
tpg/extjs-bundle 适用场景与选型建议
tpg/extjs-bundle 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 1.06k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2013 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「bundle」 「extjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tpg/extjs-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tpg/extjs-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tpg/extjs-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Utilities for easier integration of ExtJs on server-side.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Ext-JS / Sencha Touch RPC Intergration Module for Zend Framework 2
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-21