modera / direct-bundle
Symfony ExtDirect Bundle
Installs: 5 799
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 6
Forks: 1
Open Issues: 0
Type:symfony-bundle
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-10-29 03:53:26 UTC
README
ModeraDirectBundle is an implementation of ExtDirect specification to Symfony framework.
Installation
Step 1: Download the Bundle
composer require modera/direct-bundle:4.x-dev
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
This bundle should be automatically enabled by Flex.
In case you don't use Flex, you'll need to manually enable the bundle by
adding the following line in the config/bundles.php
file of your project:
<?php // config/bundles.php return [ // ... Modera\DirectBundle\ModeraDirectBundle::class => ['all' => true], ];
Step 3: Add routing
// config/routes.yaml direct: resource: "@ModeraDirectBundle/Resources/config/routing.yml"
How to use
Add the ExtDirect API into your page
If you is using Twig engine, only add the follow line in your views page at the script section:
<script type="text/javascript" src="{{ url('api') }}"></script>
Or if you are not using a template engine:
<script type="text/javascript" src="/api.js"></script>
Expose your controller methods to 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; } }
Call the exposed methods from 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); });
Licensing
This bundle is under the MIT license. See the complete license in the bundle: Resources/meta/LICENSE