soredive
soredive

Reputation: 813

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 !

Upvotes: 3

Views: 1261

Answers (2)

aajiwani
aajiwani

Reputation: 121

I have recently written a library that can provide ease in such cases. I pass the values to the required variables via name rather numbering. Also the names are included in routes to easy reference them.

May be you can have a look at it, could be useful in your case.

https://github.com/aajiwani/LaravelRoutingForCodeIgniter

Upvotes: 0

Damien Pirsy
Damien Pirsy

Reputation: 25435

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.

Upvotes: 3

Related Questions