2017 © Pedro Peláez
 

symfony-bundle ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

image

theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  • Thursday, May 14, 2015
  • by theunraveler
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,724 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

UjsBundle for Symfony 2

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links., (*1)

Dependencies

  • Symfony
  • jQuery

Installation

Install just like any other Symfony bundle. See the section below on security for further instructions., (*2)

After installing, you will need to run app/console assets:install or add @UjsBundle/Resources/public/js/ujs.js if you are using Assetic., (*3)

Usage

For any link that you would like to submit with an HTTP method other than GET, just include a data-method attribute, like so:, (*4)

<a href="/posts/15" data-method="DELETE">Delete this post</a>

You may optionally include a data-confirm attribute, which will be used as the text in the JavaScript confirm dialog., (*5)

<a href="/posts/15" data-method="DELETE" data-confirm="Are you sure you
want to delete this post?">Delete this post</a>

If you set the data-confirm attribute to false, no confirmation message will be presented. Be careful with this, though, since browsers that do link prefetching may follow the link and perform destructive actions., (*6)

Security

Important!! If you do not implement these steps, your app will be vulnerable to cross-site scripting attacks!, (*7)

First, you will need to include an HTML <meta> tag on any page that yo would like to use UJS. For example, add the following to your <head> section:, (*8)

<meta name="_ujs_csrf_token" content="{{ csrf_token('ujs') }}" />
<meta name="_ujs_csrf_token_name" content="_ujs_csrf_token" />

Any controller action that you would like to submit with UJS should check the CSRF token to make sure it is valid, like so:, (*9)

public function deleteAction(Request $request)
{
    if ($request->request->has('_ujs_csrf_token') && $this->get('form.csrf_provider')->isCsrfTokenValid('ujs', $request->request->get('_ujs_csrf_token'))) {
        // Do your deleting, posting, etc.
    }
}

The Versions

14/05 2015

dev-master

9999999-dev http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

GPL-2.0

The Requires

 

by Jake Bell

01/05 2013

1.0.5

1.0.5.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell

22/03 2013

1.0.4

1.0.4.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell

27/02 2013

1.0.3

1.0.3.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell

22/02 2013

1.0.2

1.0.2.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell

07/01 2013

1.0.1

1.0.1.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell

03/01 2013

1.0

1.0.0.0 http://github.com/theunraveler/ujs-bundle

An unobtrusive JavaScript bundle for Symfony 2. Allows for using non-GET routes with simple links.

  Sources   Download

The Requires

 

by Jake Bell