0

URL mapping can be done at .htaccess and we can edit routes.php. Learning PHP/Codeigniter, i posted this question. CodeIgniter Mod Rewrite Rules and the Controller

routes.php worked for me, and the next thing i'd like is to have access to the GET parameters in my URL. To elaborate on what i'm actually trying to do:

Case 1:

RewriteRule ^([a-z]+)/(at)/([a-z]+)$ index.php/person/show?personName=$1&place=$2 [L]

This doesn't work at the .htaccess as in the above question, but I can get that working in the routes.php

$route['([a-z]+)/at/([a-z]+)'] = "person/show/$1/$2";

If i try the routes.php as

$route['([a-z]+)/at/([a-z]+)'] = "person/show?personName=$1&place=$2";

I end up with a CodeIgniter 404. Is this fundamentally incorrect?

This works fine as is:

person/show?personName=chinmay&place=kino

Case 2:

URL which I want to expose:

chinmay?place=kino

where place is shown as a GET param. I would like to handle this, and knowing as much about routes.php-

$route['([a-z]+)\?place=([a-z]+)'] = "person/show/$1/$2"

This gives a CI 404 as well.

Community
  • 1
  • 1
Chinmay
  • 4,726
  • 6
  • 29
  • 36
  • why go so cmplicated? isnt controller/method/param1/param2/param3/paramN enough? or you might like _remap() function... In my applications i try to have as less as possible entries in routes.php simply for simplicity. I use routes.php purely when i need to translate url to local language. – Kyslik Mar 10 '14 at 00:30

2 Answers2

0

Passing URI Segments to your Functions

or

GET parameters in the URL with CodeIgniter

Community
  • 1
  • 1
Pedro Luz
  • 2,694
  • 4
  • 44
  • 54
0

You could use:

<?php

 function myFunction($param1, $param2){
  //code
 }
?>

And access it like: .../controller/myFunction/param1/param2

Gonz
  • 1,198
  • 12
  • 26