Getting started with URL routing with PHP CodeIgniter

主宰稳场 提交于 2019-12-11 20:43:33

问题


I just thought of routing my URLs which is like

http://localhost/codeigniter_cup_myth/index.php/adminController/mainAccount

and it would be pretty nice if it was

http://localhost/codeigniter_cup_myth/Accounts/mainAccount

Where should I start when routing URLs in my web application?


回答1:


Also, adding something like:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

to your .htaccess file will get rid of the index.php part




回答2:


Routes are defined as such:

$route['product/:num'] = "catalog/product_lookup";

where product / anynumber is your URL: http://www.example.com/product/234. The second part is the controller/method. The URL we're talking about here would call the catalog controller's product_lookup method.

$route['accounts/mainaccount'] = "adminController/mainAccount"

Would fire what you're looking for. Take a look at the CodeIgniter User Guide for more examples.

I use this .htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Which allows any physically existing file to be accessed, all else is routed to CI.




回答3:


u can check woo url routing component

http://code.google.com/p/woo/

woo url routing feature:

  1. easy to add custom and dynamic routing url to route collection.
  2. easy to create constraits which restrict URLs that match a paticure route.
  3. supporting catchall style in the route match.
  4. using route debugger to show routes match status in route collection when directly type URL address in the browser address bar.
  5. creating custom route handler to process the URL that match a paticular route in the route collection.


来源:https://stackoverflow.com/questions/2584571/getting-started-with-url-routing-with-php-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!