Issue
A complex web-app can have a large amount of user and/or context specific meta and configuration information. eg, user's preferred result-set size, timezone, beginning of the week (Sun/Mon), etc.
What are the possible ways to transport the variables to the client application as it is loading (hidden variables? JSON embedded somewhere?), and what are the pros/cons of each method?
I know of a few ways to hack things together, but I'm curious if anyone has identified good design patterns to use, or best practices they can share.
Although I'd prefer general info on this, my primary stack is jLAMP (jQuery, Apache, MySQL, PHP)
EDIT: I already have applications that do this, so I'm not looking for a quick fix, or suggestions for an entirely different paradigm (as in, not loading config). I'm looking for a discussion with the options and pros/cons of each, so that I might tune what I have, or a new user would be presented with plenty of options to make a good design decision from the start. Thanks!
Solution
For me it's passing in a JSON array. It's so flexible on the client side I'm not sure why you wouldn't use it. On the backend I build it up using a regular PHP array and then just convert it to JSON using json_encode before echoing to the webpage.
<script>var myObject = <?=$mySettings?></script>
and you're good to go. As a bonus I just convert the json object to a string before I pass it back to PHP using a single variable in a post and convert it back to a PHP array for manipulation and inclusion into a database.
Answered By - Dustin Nielson
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.