How does the ZF framework assign an array allocated on the php page to a JS variable on the template page? Allocate variables on the controller page: $ this-& gt; view-& gt; request $ request; $ request is an array. how can I assign this $ request to a JS variable in JS on the template page? ------ Solution ------------------ how does one get an ZF framework in the template page to assign an array allocated on the php page to a JS variable on the template page?
Allocate variables on the controller page:
$ This-> view-> request = $ request; // $ request is an array
How can I allocate this $ request to a JS variable in JS on the template page?
------ Solution --------------------
Create a hidden, value = {$ Js_Request} on the template page}
Assign a value to the variable in the controller: assgin ("Js_Request", $ request );
Take the value of this hidden in js: var Js_Request = id_hidden.value;
------ Solution --------------------
Json_encode?
------ Solution --------------------
Can json_encode convert php Data into js data?
------ Solution --------------------
You can parse the array into a string or json, and the front-end js can be converted into an array again.
However, json data is better and js can be used directly.