Php Get
Allows to get variables from PHP.
Installation
Download and install npm at www.npmjs.com/get-npm if you haven't already.
npm install php-get --save
This package is provided in ES6 module format.
Usage
To transmit variables to your js, you must write hidden input like this :
<input type="hidden" id="phpGet_var1" value=""My example string"" />
<input type="hidden" id="phpGet_var2" value="["The first element of my example array", "The second element of my example array"]" />
Notice that the value must be in JSON format, and that the double quotes are replaced with """. In js, you have to do that :
import phpGet from 'php-get';
var var1 = phpGet('var1');
var var2 = phpGet('var2');
console.log(var1); // We obtains : "My example string"
console.log(var2); // We obtains an array : ["The first element of my example array", "The second element of my example array"]
You can specify a default value, in case if the variable is not transmited. For example :
import phpGet from 'php-get';
var var3 = phpGet('var3', "This variable doesn't exists.");
console.log(var3); // We obtains : "This variable doesn't exists"