php - Custom URL Helper redirect with get method -
on codeigniter application/helper/my_url_helper able add '?&route=' . $uri
able use '?&route='
after index.php before first folder / function.
but every time click on link url changes page stays same?
question: on helper how can add '?&route=' . $uri
make still redirect page each time when click on link url changes page stays same?
redirect('common/dashboard');
url http://localhost/project/admin/?&route=common/dashboard
i have tried routes , same issue.
<?php if ( ! function_exists('redirect')) { function redirect($uri = '', $method = 'auto', $code = null) { //if ( ! preg_match('#^(\w+:)?//#i', $uri)) //{ $uri = site_url('?&route=' . $uri); //} // iis environment likely? use 'refresh' better compatibility if ($method === 'auto' && isset($_server['server_software']) && strpos($_server['server_software'], 'microsoft-iis') !== false) { $method = 'refresh'; } elseif ($method !== 'refresh' && (empty($code) or ! is_numeric($code))) { if (isset($_server['server_protocol'], $_server['request_method']) && $_server['server_protocol'] === 'http/1.1') { $code = ($_server['request_method'] !== 'get') ? 303 // reference: http://en.wikipedia.org/wiki/post/redirect/get : 307; } else { $code = 302; } } switch ($method) { case 'refresh': header('refresh:0;url='.$uri); break; default: header('location: '.$uri, true, $code); break; } exit; } }
.htaccess
options +followsymlinks options -indexes directoryindex index.php rewriteengine on rewritecond $1 !^(index\.php|images|robots\.txt) rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ index.php/$1 [l,qsa]
update:
version of codeigniter using 3
in config use
tried with
$config['uri_protocol'] = 'request_uri';
and
$config['uri_protocol'] = 'query_string';
but saying page not found?
page there though.
also "common" folder
and "dashboard" controller
all controllers have first letter upper case dashboard.php
note: have tried enable query strings on config.php not work way after.
first steps had solve was
in routes.php
$get_route_method = 'route='; $route[$get_route_method . 'common/dashboard'] = "common/dashboard/index";
seems work fine when manually added route in application/config/route.php
then in my_url_helper in application/helper.php $uri = site_url('index.php?route=' . $uri);
<?php if ( ! function_exists('redirect')) { function redirect($uri = '', $method = 'auto', $code = null) { if ( ! preg_match('#^(\w+:)?//#i', $uri)) { $uri = site_url('index.php?route=' . $uri); } // iis environment likely? use 'refresh' better compatibility if ($method === 'auto' && isset($_server['server_software']) && strpos($_server['server_software'], 'microsoft-iis') !== false) { $method = 'refresh'; } elseif ($method !== 'refresh' && (empty($code) or ! is_numeric($code))) { if (isset($_server['server_protocol'], $_server['request_method']) && $_server['server_protocol'] === 'http/1.1') { $code = ($_server['request_method'] !== 'get') ? 303 // reference: http://en.wikipedia.org/wiki/post/redirect/get : 307; } else { $code = 302; } } switch ($method) { case 'refresh': header('refresh:0;url='.$uri); break; default: header('location: '.$uri, true, $code); break; } exit; } }
Comments
Post a Comment