2017 © Pedro Peláez
 

library javascript-data-bundle

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

image

najidev/javascript-data-bundle

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

  • Tuesday, August 6, 2013
  • by Naji
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

NajiDevJavaScriptDataBundle

This bundle integrates \NajiDev\Common\JavaScriptData\Container into your project in a nice way, for having a bridge to get php variables to javascript. Take a look on the documentation of najidev/common., (*1)

Installation

Add bundle to composer.json

As composer is the standard way of Symfony to handle libraries and bundles, i'll only show the installation with composer. In your composer.json add following:, (*2)

"require" : {
    "najidev/javascript-data-bundle" : "@dev"
}

You should consider taking one of the releases instead of "@dev"., (*3)

Load the bundle in your Kernel

$bundles = array(
    // your current bundles

    new \NajiDev\JavaScriptDataBundle\NajiDevJavaScriptDataBundle(),
);

Usage

The bundle creates the service, (*4)

najidev.common.javascriptdata.container

in your DIC, which is an instance of, (*5)

\NajiDev\Common\JavaScriptData\Container

You just need to grab it by the DIC in your controller and use it:, (*6)

$this->get('najidev.common.javascriptdata.container')->set('my.key', 'value');

Another way to interact with the data-container is the templating helper:, (*7)

$view['javascript_data']->set('my.key', 'value');

When it comes to display the data, the helper has another method:, (*8)

<?php echo $view['javascript_data']->render(); ?>

Just use that simple line in a layout and your data can everywhere be grabbed by the helper.js. Be sure to use the helper.js, when the body was completely rendered. Jquerys ready-event is just perfect for that:, (*9)

<script>
    $(document).ready(function()
    {
        var value = jsd.get('my.key', 'a default value, which will be returned if such key does not exist');

        console.log(value);
    });
</script>

The Versions

06/08 2013

dev-master

9999999-dev

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

  Sources   Download

MIT

The Requires

 

php javascript variable bridge

18/03 2013

1.0.2

1.0.2.0

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

  Sources   Download

MIT

The Requires

 

php javascript variable bridge

16/03 2013

1.0.1

1.0.1.0

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

  Sources   Download

MIT

The Requires

 

php javascript variable bridge

10/11 2012

1.0.0

1.0.0.0

Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way

  Sources   Download

MIT

The Requires

 

php javascript variable bridge