Tengo una API que utilizó siempre URLs segment-based (http://ellislab.com/codeigniter/user-guide/general/urls.html)
Sin embargo, al tener que desarrollar una interfaz, la cual recibe peticiones vía GET con el típico formato query-string based, obtenia en CI el error 404 – Página No Encontrada porque la aplicación intentaba aplicar las reglas de segmento de URI y estas estaban en un formato no compatible, pero otras secciones de la aplicación debian mantenet este formato. Asique me encontré en el problema de ajustar la configuración para que acepte tanto formato segment-based:
www.example.com/controllername/methodname/id1/id2
como el formato query string:
www.example.com/?c=contname&m=methodname?id=23
PERO ADEMÁS, las dos opciones deben poder trabajar juntas:
example.com/controllername/methodname/?param1=123¶m2=321¶m3=789
Como se ve, necesito «mezclar» ambos formatos de URL. Investigando bastante, encontré una forma que funcionó ok para mi:
1) SI USAS CODEIGNITER 1.5.X ===> Editar config.php y cambiar la linea:
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
//$config['uri_protocol'] = "AUTO";
$config['uri_protocol'] = "ORIG_PATH_INFO";
1) SI USAS CODEIGNITER 2.0.X ===> Editar config.php y cambiar la linea:
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
//$config['uri_protocol'] = "AUTO";
$config['uri_protocol'] = "REQUEST_URI";
Y verificar que la linea : $config[‘enable_query_strings’] = FALSE;
/*
|--------------------------------------------------------------------------
| Enable Query Strings
|--------------------------------------------------------------------------
|
| By default CodeIgniter uses search-engine friendly segment based URLs:
| example.com/who/what/where/
|
| You can optionally enable standard query string based URLs:
| example.com?who=me&what=something&where=here
|
| Options are: TRUE or FALSE (boolean)
|
| The other items let you set the query string "words" that will
| invoke your controllers and its functions:
| example.com/index.php?c=controller&m=function
|
| Please note that some of the helpers won't work as expected when
| this feature is enabled, since CodeIgniter is designed primarily to
| use segment based URLs.
|
*/
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'; // experimental not currently in use
Continúe tal y como está en FALSE.
Luego dentro de tu controlador, para bajar los parámetros puedes utilizar la siguiente función privada:
protected function getQueryStringParams() {
parse_str($_SERVER['QUERY_STRING'], $params);
return $params;
}
public function index(){
$params = $this->getQueryStringParams();
var_dump($params);
.........
}
Sin comentarios a “Como utilizo query strings en conjunto con las URLs segment-based proporcionadas por CODE IGNITER | How to use segment-based AND query strings URLs in Code Igniter”
Por favor espera
Deja una respuesta