I am actualy getting to use coldbox for the first ...
# box-products
t
I am actualy getting to use coldbox for the first time so a nb question but is there a way to pass an array of integers in the url, e.g
Copy code
foo=[1,2,3,4] -> /foo/[some array notation]
c
URL params are always simple values, not complex variables like structs or arrays. So if you pass
?foo=[1,2,3,4]
it will be seen as a string beginning with a square bracket. This has nothing to do with ColdBox though, it's just the way URL params are handled. You can try easily with a simple test page:
Copy code
<cfdump var="#url#">
<cfoutput>#isArray( url.foo )#</cfoutput>
t
yes i was just hoping there was some coldbox magic that turned foo/1/2/3/4 into foo = [1,2,3,4] but I will just send them as lists
c
Another possibility: if you can pass URLs like
/?foo=1&foo=2&foo=3&foo=4
and in your Application.cfc set
this.sameFormFieldsAsArray = true
, then the incoming URL variable
foo
should be an actual array (
[1,2,3,4]
).
One other approach I've seen in other web apps (not necessarily a ColdFusion app) is to pass a URL parameter that contains URL-encoded JSON. So your desired
foo=[1,2,3,4]
would become
foo=%5B1%2C2%2C3%2C4%5D
. CF should automatically decode that to a JSON string, which you could then use
deserializeJSON
to convert to an array. This approach can be used for more complex data structures (like structs, arrays, or nested combinations of both).
👍 1