modera / direct-bundle
Symfony ExtDirect 扩展包
v3.1.0
2021-10-13 06:33 UTC
Requires
- php: >=5.6
- symfony/framework-bundle: ^3.4|^4.0
- dev-master / 4.x-dev
- 3.x-dev
- v3.1.0
- v3.0.0
- 2.x-dev
- v2.57.0
- v2.56.0
- v2.55.0
- v2.54.0
- v2.53.0
- v2.52.2
- v2.52.1
- v2.52.0
- v2.51.1
- v2.51.0
- v2.0.50
- dev-sf3
- dev-direct-bundle-csrf
- dev-crub_pagination_fetch_fix
- dev-MPFE-1005
- dev-MPFE-1007
- dev-MPFE-1014
- dev-MPFE-1014-2
- dev-MPFE-1017
- dev-MPFE-1029
- dev-MPFE-963
- dev-MPFE-975
- dev-MPFE-977
This package is auto-updated.
Last update: 2024-08-29 03:15:48 UTC
README
ModeraDirectBundle 是 ExtDirect 规范在 Symfony 框架中的实现。
安装
步骤 1: 下载扩展包
composer require modera/direct-bundle:4.x-dev
此命令要求您全局安装 Composer,如 Composer 文档中的安装章节所述。
步骤 2: 启用扩展包
此扩展包应通过 Flex 自动启用。如果您不使用 Flex,您需要手动在项目的 config/bundles.php
文件中添加以下行以启用扩展包
<?php // config/bundles.php return [ // ... Modera\DirectBundle\ModeraDirectBundle::class => ['all' => true], ];
步骤 3: 添加路由
// config/routes.yaml direct: resource: "@ModeraDirectBundle/Resources/config/routing.yml"
如何使用
将 ExtDirect API 添加到您的页面
如果您使用 Twig 引擎,只需在视图页面的脚本部分添加以下行
<script type="text/javascript" src="{{ url('api') }}"></script>
或者如果您不使用模板引擎
<script type="text/javascript" src="/api.js"></script>
将控制器方法暴露给 ExtDirect Api
// .../Acme/DemoBundle/Controller/ExampleController.php namespace Acme\DemoBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Modera\DirectBundle\Annotation\Remote; use Modera\DirectBundle\Annotation\Form; class ExampleController extends AbstractController { /** * Single exposed method. * * @Remote // this annotation expose the method to API * * @param array $params * @return string */ public function indexAction(array $params) { return 'Hello ' . $params['name']; } /** * An action to handle forms. * * @Remote // this annotation expose the method to API * @Form // this annotation expose the method to API with formHandler option * * @param array $params Form submitted values * @param array $files Uploaded files like $_FILES */ public function testFormAction(array $params, array $files) { // your proccessing return true; } }
从 JavaScript 调用暴露的方法
// 'AcmeDemo' is the Bundle name without 'Bundle' // 'Example' is the Controller name without 'Controller' // 'index' is the method name without 'Action' Actions.AcmeDemo_Example.index({ name: 'ExtDirect' }, function(r) { alert(r); });
许可
此扩展包采用 MIT 许可。请参阅扩展包中的完整许可:Resources/meta/LICENSE