Passing Information via GET Parameters #456
pchemguy
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Thanks for sharing ! Depending on your requirements, you can also use cookies to persist user preferences such as language or theme between page loads. This avoids having to reconstruct complex urls in all links. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Web applications routinely use URL GET parameters to pass information between different application parts. For example, when an unauthenticated user clicks the Login button, the browser redirects to the login form. Depending on specific circumstances, the application usually would want to redirect back to the original page after the authentication process is completed. A common approach to pass the desired return path to the login form is via a GET parameter. In SQLPage, one could do something like this:
Other common examples of using GET parameters include querying various databases and search engines and passing certain context information between application components. In such cases, it might also be necessary to relay other GET parameters when redirecting.
SQLPage provides the
sqlpage.variables('GET')
function returning a JSON array containing current GET parameters. This JSON array also contains any locally set variables via the SET statement, which, generally, do not need to be passed around indiscriminately. As far as I can tell, SQLPage does not provide a readily available means to distinguish the two kinds of variables. One possible approach to separate the two is via a naming convention. I usually prefix local variable names with underscores. For instance, path information may be stored in a local variable for further use:which can later be used to set a redirect or action target:
If this "underscore" convention is adopted, the code inside an SQLPage script may retrieve GET parameters:
This code may be executed at the top of a page to "prepare" the environment. Given a URL containing
?lang=en&theme=fancy&hide_language_names=1&authenticated=0
,$_get_vars
will be set toSuppose we plan to populate language submenu links that enable switching to alternative locales. Given a table with a list of available languages:
we could have
index.sql
with the following minimalistic code:Beta Was this translation helpful? Give feedback.
All reactions