Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use hyphen(-) instead of slash(/) or underscore( _ ) in Routes

I'm Using Codeigniter 3.x , Using routes.php I want to create dynamic routes, for example I have a class name Class1.

I want output url

mysite.com/Class1-Student-Search

But using hyphen(-) is not working

If I put a slash(/), it works,

$route['(:any)/Student-Search']  = "search";

it returns

mysite.com/Class1/Student-Search

and using underscore (_) also work.

$route['(:any)_Student-Search']  = "search";

returns

mysite.com/Class1_Student-Search

But I want to use hyphen(-), if I put it, it will go to 404 error page, I used these four solutions but not work for me.

$route['(:any)-Student-Search']  = "search";
$route['([a-zA-Z]+)-Student-Search']  = "search";
$route['([a-zA-Z-0-9]+)-Student-Search']  = "search";
$route['(.*)-Student-Search']  = "search";

And if i hardcode the value in route

$route['Class1-Student-Search']  = "search";

Then it also working

like image 770
Maninderpreet Singh Avatar asked Nov 09 '22 14:11

Maninderpreet Singh


1 Answers

You trying to create a dynamic routes which is not possible in codeigniter if you see the following flow chart of codeigniter you understand what i mean.

enter image description here

also you can see this chart in codeigniter official website

when you try to redirect or call some url it's work like this

enter image description here

Every request first goes to route there for you can't make it dynamic

like image 127
Yaseen Ahmad Avatar answered Nov 14 '22 22:11

Yaseen Ahmad