soredive soredive - 7 months ago 25
PHP Question

codeigniter route problem

result I want :

greeting/102/steve => greeting/index/102/steve


in greeting.php :

function index($order,$name)
{
echo "order: $order , name : $name ! ";
}


in route.php :

$route['greeting/(:num)/(:any)'] = "greeting/index/$1/$2";


result I get :

order : , name : steve !

Answer

Actually, it's right to use double quotes. It's even indicated like this in the manual (beside having done it a hundred times), so I don't see the problem @cwallenpool is pointing out.
Your routing looks fine, be sure it is called after the reserved routes

$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['greeting/(:num)/(:any)'] = "greeting/index/$1/$2";

.
I suggest you to try using $this->uri->rsegment(n) (info on user guide here) to catch the rerouted uri segment that's causing you trouble. (similar to $this->uri->segment(n) but designed specifically for rerouted URIs)

You can also try changing the $config['uri_protocol'] from AUTO to PATH_INFO (or one of the other alternatives) and see if the problem doesn't sit there. Remember also to delete the 'index.php' part in $config['index_page'] if you're using htaccess to delete the index.php from you URL.