de message: CodeIgniter PHP Framework - Need to get query string
Voici un exemple complet de travail de la façon de permettre querystrings dans CodeIgnitor, comme sur la plate-forme JROX. Il suffit d'ajouter ceci à votre fichier config.php situé à:
/system/application/config/config.php
Et vous pouvez simplement obtenir les querystrings comme normale en utilisant $ _GET ou la classe ci-dessous
$yo = $this->input->get('some_querystring', TRUE);
$yo = $_GET['some_querystring'];
Voici le code pour faire tout ce qu'il travail:
/*
|--------------------------------------------------------------------------
| Enable Full Query Strings (allow querstrings) USE ALL CODES BELOW
|--------------------------------------------------------------------------*/
/*
|----------------------------------------------------------------------
| 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
|
*/
if (empty($_SERVER['PATH_INFO'])) {
$pathInfo = $_SERVER['REQUEST_URI'];
$index = strpos($pathInfo, '?');
if ($index !== false) {
$pathInfo = substr($pathInfo, 0, $index);
}
$_SERVER['PATH_INFO'] = $pathInfo;
}
$config['uri_protocol'] = 'PATH_INFO'; // allow all characters
$config['permitted_uri_chars'] = ''; // allow all characters
$config['enable_query_strings'] = TRUE; // allow all characters
parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
Profitez :-)
pourquoi voulez-vous utiliser des variables $ _GET, lorsque vous pouvez utiliser des URL réécrite Achi avez-vous le même but dans CodeIgniter? – GSto
bien, la seule raison pour laquelle je m'accepterais serait de soutenir les URL héritées. J'ai un client qui aimerait beaucoup passer à des URLs amicales, la possibilité existe de refaire leur site web "code spaghetti" en utilisant un framework, mais codeigniter ne permettra pas à leur nouveau site de supporter plusieurs dizaines de milliers (!) liens entrants à divers articles, vous comprenez pourquoi c'est inacceptable :) –
La nouvelle solution consiste à utiliser [CodeIgniter Reactor] (https://bitbucket.org/ellislab/codeigniter-reactor), qui prend en charge GET correctement hors de la boîte. –