开发者

Rewrite my main controller (home), So I don't see it in the URL, is this possible?

I have a code igniter project, I have used Mod_rewrite to remove the "index.php" from url's using this method. This works fine.

But now, I would like to remove my开发者_Python百科 main controller (ie, default_controller) in config/routes.php which is named "Home".

So Basically, my current url is:

http://localhost:85/project/Home/portfolio
http://localhost:85/project/Home/about_me

I want it to be:

http://localhost:85/project/portfolio      // Get rid of the "Home"
http://localhost:85/project/about_me       // Get rid of the "Home"

And if I use another controller apart from "Home" (My main controller), I want it to be displayed in the URL as normal.

So if I create a controller named "Blog", I want to be able to use "Blog" in the URL, so I dont want to get rid of this, because its not the default_controller.

So I should be able to access Blog methods as usual like so:

// Here I want to see the Blog Controller -> Then -> Method Name as usual.
http://localhost:85/project/Blog/entry/1
http://localhost:85/project/Blog/create
http://localhost:85/project/Blog/delete

I'm not good at all with mod_rewrite so any sort of simple explanation would suffice.


[EDIT]

Can anyone tell me if this is even possible?

What else can I name my controller to look good in a browser rather then "Home"?


Of course just because you've named the controller "Home" doesn't make it any different from another controller. There is not so much a default controller as there is a default page (if no URL segments are present), which is defined in your routes.php. You can also use routes to map requests within CI instead of .htaccess (exactly what they're for):

$route['portfolio'] = 'home/portfolio';
$route['about_me'] = 'home/about_me';

// Alternative
$route['(portfolio|about_me)'] = 'home/$1';

This basically says: "If the user requests $key, give them $value". Routes are awesome, definitely worth learning how to use to your advantage.

Read more: http://codeigniter.com/user_guide/general/routing.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜