How the ZF framework assigns an array allocated on the php page to a JS variable on the template page-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.