简体   繁体   中英

Fat Free PHP SEO Friendly URLs

I'm looking into using F3 for more of my projects. I love the routing feature and the ability to produce dynamic routes for using with conventions like:

$f3->route('GET /@controller/@action', '@controller->@action');

One thing I need is seo-friendly URLs so I can do something like:

/two-words/two-more-words 

as a controller/action combo. I've tried this in code as well as searched as far as I can see for examples on how to accomplish this, but thus far, I've been unsuccessful. Basically, the dash in the url will not resolve to a class/method (controller/action) combo in the routes.

Is there a way to do this so that dashes either get replaced by empty characters or some other way to get the routes to resolve?

well if you really want it that way you could use a lambda function for this:

f3->route('GET /@controller/@action', function($f3,$params){
  $class = str_replace('-','',$params['controller']);
  $method= str_replace('-','',$params['action']);
  $f3->call( $class.'->'.$method );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM