CodeIgniter uri's - ¿cómo obtener múltiples valores?

I am using a form to submit filter parameters for a view. There are multiple filters that can be selected, and some filters are multi-selects.

However, I would prefer to use the post-redirect-view method, which means that I have to translate the post data to uri segments.

With this in mind, I was going to use the $this->uri->uri_to_assoc(n) method. However, I am not sure how to get this working if some of the parameters can have multiple values.

The only method I can think of is to join the values for each key with a unique character (say ‘—’), use $this->uri->uri_to_assoc(n) to parse each key-value pair, and then explode() each of the values (on ‘—’) again. Is this the best way to do it?

In addition, how do you get over the issue that one of the values may have a forward slash (’/’) in the name?

Ejemplo:

I have a multi-select (named categories[]) that is posted and used to filter parameters. The user select 2 values from this multiselect: 'Jim/Bob' and 'Sarah'. Controller receives the post, $this->input->post('categories') gives me an array. I now want to redirect back to the same controller and use the values from $this->input->post('categories') as parameters in the uri. It would be something like /controller/method/categories/abc dónde abc are the categories selected.

dónde

preguntado el 09 de marzo de 12 a las 14:03

could you show an example of the uri you want to work out? -

please be more specific, show what you have and what you want to get in result. -

IMO, you should use the Biblioteca de entrada y $_GET parameters like so: $filters = $this->input->get('filters'). -

2 Respuestas

This is actually a good case for using the "GET" form method. You're not receiving input from the user, but the user is querying information. The Post-Redirect-Get pattern isn't relevant in this context.

Use the query string ;)

respondido 09 mar '12, 20:03

In the end, I just manually created the query string using http_build_query($query_array) and parse_str($_SERVER['QUERY_STRING'], $get);

respondido 19 mar '12, 15:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.