开发者

dynamic action names in codeigniter or any php mvc framework

开发者 https://www.devze.com 2022-12-23 12:57 出处:网络
I\'ve noticed many sites are able to use a username or page title as an action. How is this done? For example instead of www.example.com/users/my_username (where the users action 开发者_开发问答is ge

I've noticed many sites are able to use a username or page title as an action. How is this done?

For example instead of www.example.com/users/my_username (where the users action 开发者_开发问答is generic and responsible for fetching user data) how could I make this www.example.com/my_username?

Thanks very much.


All modern frameworks follow router ideology. So for this task you just need to write yet another route.

How to do this - is a specific task for particular framework.


In CodeIgniter it would be a route like zerkms said. You can define routs in /system/application/config/routes.php. Here's the CodeIgniter documentation on URI routing. Essentially you take the part of the URL (such as the username) specified in your route as a variable and can do a lookup against your db with it.


With mod_rewrite you could write a rule that redirects www.example.com/user/my_username (or without the user) to www.example.com/user/?name=my_username.

0

精彩评论

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