According to CI's docs, CodeIgniter uses a segment-based approach, for example:
example.com/my/group
If I want to find a specific group (id=5), I can visit
example.com/my/group/5
And in the controller, define
function group($id='') {
...
}
Now I want to use the traditional approach, which CI calls "query string" URL. Example:
example.com/my/group?id=5
If I go to this URL directly, I get a 404 page not found. So how can I enable this?
In order to use Query String URL's, edit config. php which is located in application/config. Set 'enable_query_strings' to TRUE and define controller and function trigger.
$currentURL = current_url(); $params = $_SERVER['QUERY_STRING']; $fullURL = $currentURL .
CodeIgniter's URL helpers are groups of utility functions which will help you to call ,create and maintain url. It mainly have more than 20 helpers some of them you might be familiar with are URL, email, form etc. These are some common helper functions that generaly used in web based application for email, files, URLs.
For reliable use of query strings I've found you need to do 3 things
application/config/config.php
set $config['enable_query_strings'] = true;
application/config/config.php
set $config['uri_protocol'] = "PATH_INFO";
I use the following
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
//Add this method to your (base) controller :
protected function getQueryStringParams() {
parse_str($_SERVER['QUERY_STRING'], $params);
return $params;
}
// Example : instagram callback action
public function callback()
{
$params = $this->getQueryStringParams();
$code = !empty($params['code']) ? $params['code'] : '';
if (!empty($code))
{
$auth_response = $this->instagram_api->authorize($code);
// ....
}
// .... handle error
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With