Download the PHP package najidev/javascript-data-bundle without Composer
On this page you can find all versions of the php package najidev/javascript-data-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download najidev/javascript-data-bundle
More information about najidev/javascript-data-bundle
Files in najidev/javascript-data-bundle
Package javascript-data-bundle
Short Description Integrates \NajiDev\Common\JavaScriptData\Container in your project in a nice way
License MIT
Informations about the package javascript-data-bundle
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.
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:
"require" : {
"najidev/javascript-data-bundle" : "@dev"
}
You should consider taking one of the releases instead of "@dev".
Load the bundle in your Kernel
$bundles = array(
// your current bundles
new \NajiDev\JavaScriptDataBundle\NajiDevJavaScriptDataBundle(),
);
Usage
The bundle creates the service
najidev.common.javascriptdata.container
in your DIC, which is an instance of
\NajiDev\Common\JavaScriptData\Container
You just need to grab it by the DIC in your controller and use it:
$this->get('najidev.common.javascriptdata.container')->set('my.key', 'value');
Another way to interact with the data-container is the templating helper:
$view['javascript_data']->set('my.key', 'value');
When it comes to display the data, the helper has another method:
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:
<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>
All versions of javascript-data-bundle with dependencies
symfony/config Version >=2.0,<2.3-dev
symfony/dependency-injection Version >=2.0,<2.3-dev
symfony/http-kernel Version >=2.0,<2.3-dev
symfony/templating Version >=2.0,<2.3-dev
najidev/common Version >=1.0.1