mikoweb / symfony-backbone-bundle
Installs: 135
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Type:symfony-bundle
Requires
- php: >=5.4.0
- symfony/form: ~2.3
- symfony/framework-bundle: ~2.3
This package is not auto-updated.
Last update: 2016-12-31 08:52:10 UTC
README
Add the bunde to your composer.json
file:
require: { "mikoweb/symfony-backbone-bundle": "~0.2" }
Register the bundle with your kernel:
// in AppKernel::registerBundles() $bundles = array( // ... new SymfonyBackboneBundle\SymfonyBackboneBundle(), );
Execute the following command:
assets:install --symlink
Put in the code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script> <script type="text/javascript" src="{{ asset('bundles/symfonybackbone/js/symfony-backbone.js') }}"></script>
Symfony forms
Model binding example:
var Model = Backbone.symfony.ModelForm.extend({ formPrefix: 'foo' }), model = new Model(), form = $('form[name="foo"]');
form.on("submit", function (e) { e.preventDefault(); model.bindForm(e.target); model.save(); });
Receive data in your controller:
$form = $this->createForm(new FooFormType()); $manager = $this->get('backbone.manager.form'); $manager->hanadleRequest($form, $request); // do something return new JsonResponse([ 'data' => $manager->getFormData($form), 'submitted' => $form->isSubmitted(), 'valid' => $form->isValid(), 'errors' => $manager->getErrorsArray($form), ]);
Autobindig data:
view = new Backbone.symfony.ViewForm(); view.setModelForm(model); view.setFormElement(form); form.on('submit', function (e) { model.save(); e.preventDefault(); });
Turn off autobinding...
view.offFormElement();