How to pass an array to a controller? |
[eluser]gminuses[/eluser]
I'd like to pass an array as a parameter to my controller, the parameters number is unknown, but the last one is the array I want to pass in. So how do I write the url? I'm looking for something like: http://localhost/mycontroller/myaction/p...l2+arrVal3 that codeigniter will convert the last parameter into an array. Is it possible? Thanks.
[eluser]imn.codeartist[/eluser]
why don't you push into session instead of doing that... will have less headache if you do so :-)
[eluser]gminuses[/eluser]
The request is made by front end, it has no idea of session.
[eluser]rogierb[/eluser]
Serialize and urlencode it Code: $test = array(1,2,3,4); and in your controller Code: $array = unserialize(rawurldecode($the_serialized_array)); Not tested:-)
[eluser]gminuses[/eluser]
This isn't SEO friendly, and if the client side is not generated by php(i.e, pure html + js), serialize & rawurlencode functions will have to be reimplemented. Anyway, thank you for the reply.
[eluser]Boris Strahija[/eluser]
Why wouldn't you use sessions for this. For me this would be the most logical sollution. A front end fo an application can also have sessions Other suggestions would be passing the array by form submission, or storing it into a database, but every user would then need some kind of a token, so that's actually a session You can also write the data into a txt file, but I don't think that's a good idea, because of security issues. My suggestions is, use session. If possible with a database, because in this way you can store much more data into a session. If you use a cookie the data size is limited.
[eluser]gminuses[/eluser]
Could you tell me more about client side session and how to implement it? If the values in the array is generated by javascript(client side), how do I pass these values to a controller as the last parameter, along with other values as the rest of paramters? Using form submission will force it becoming a post request.
[eluser]gminuses[/eluser]
Like you said, the cookie data size is limited, and the user might has disabled cookies.
|
Welcome Guest, Not a member yet? Register Sign In |