Am very new to CI, So I want to know that one feature listed below will be done via CI Router, then How开发者_如何学C?
Feature:
Q1. I need to show my users profile in such a way that mysite.com/johhn
mysite.com/raju.radha
mysite.com/johhn1
.
Q2. Other Urls are mysite.com/photo/3434
, mysite.com/album/3443
etc etc.
I know this can be achieved by using $route
. for the Q2 this is the solution
$route['photo/:num'] = "photo/photo_list";
$route['album/:num'] = "album/album_list";
and what is the solution for Q1??
Thanks in advance !!!
Route:
$route['(:any)'] = "profile/view/$1";
Controller:
class Profile extends CI_Controller {
function view($username) {
echo $username;
}
}
Edit: Commenter made the great point that this will need to be the last route directive in the file to prevent it from overriding all of the other routing rules.
精彩评论