开发者

CodeIgniter: Simple URL routing question

I'm new to CI and URI routing in general.

I created a new app. Set the default controller to Main. In Main, I have an index method, a po开发者_如何学Pythonpular method and a recent method.

When I load my app, the url shows up as http://localhost/myapp... this obviously loads up the index method in the Main controller... that's fine.

Now how do I route my URIs so I can load up the popular and recent method by going to http://localhost/myapp/popular and http://localhost/myapp/recent respectively?


You can use CodeIgniter's routing features. To do that, just add the following lines to your application/config/routes.php file:

$route['recent'] = "main/recent";
$route['popular'] = "main/popular";


$route['recent'] = "your_controller/recent";
$route['popular'] = "your_controller/popular";

That's what you will need. Any call to "recent" will route to "your_controller/recent". The same goes with popular.


If popular and recent are actual pages in your application, as opposed to functions, you ought to move those to their own controllers, as opposed to keeping them under main.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜