Reputation: 747
Codeigniter routing rules don't seem to pick up anything after a slash for me - is this the default behaviour - how can I prevent it?
Example:
In routes.php:
$route['blog/read-post/(.+)'] = 'blog/lookup_blog_alias/$1';
In controller:
function lookup_blog_alias($str){
print $str;
}
If I enter a url such as:
http://localhost/blog/read-post/a-b-c/12
I only get the "a-b-c" part when what I would like is "a-b-c/12".
Thanks for any help.
Upvotes: 1
Views: 2571
Reputation: 7993
No, by default, your requirement will only work if you change the route URL & the controller method to something like this:-
$route['blog/read-post/(.+)/(.+)'] = 'blog/lookup_blog_alias/$1/$2';
// Controller Method
function lookup_blog_alias($str1, $str2){
print $str1.'/'.$str2;
}
You need to follow the basics of the CodeIgniter User Guide, where it says that it's the convention of CI to mark a limit of string with the character "/
" (forward-slash). It simply means that in between two forward-slashes, the following things can / may be considered in a general MVC Framework:-
However, in the "routes.php
" page of CodeIgniter, the logic can be changed by the virtue of HTAccess. Still the above concept stands straight & so it will be wise to follow the normal MVC architecture.
Hope it helps.
Upvotes: 2