rosio/php-to-javascript-variables

There is no license information available for the latest version (v1.0.1) of this package.

v1.0.1 2014-06-18 05:00 UTC

This package is not auto-updated.

Last update: 2024-12-21 16:41:24 UTC


README

Build Status

Simple package which allows easy sharing of variables from PHP to JavaScript. This is a rewrite of the laracasts/utilities package. I was prompted to do this due to the aformentioned package requiring PHP 5.4+, and I disliked their design.

Installation

composer.json

"require": {
	...
	"rosio/php-to-javascript-variables": "~1.0"
}

config/app.php

'providers' => array(

	...
	'Rosio\PhpToJavaScriptVariables\PhpToJavaScriptVariablesServiceProvider',

),

Usage

controllers\HomeController.php

	public function showWelcome()
	{
		JSLocalize::put(array(
			'variableName' => 'variableValue',
			'anotherVariable' => array(1, 2, 3)
		));

		return View::make('hello');
	}

views\hello.php

<!doctype html>
<html lang="en">
<head>
	...
	{{ App::make('JSLocalizeDumper')->dump() }}
	...
</head>
<body>

	<script type="text/javascript">
		alert(app.variableName);
	</script>
</body>
</html>