dounuo1881 2014-08-25 15:00
浏览 38
已采纳

无脂PHP SEO友好的URL

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?

  • 写回答

1条回答 默认 最新

  • dpxua26604 2014-08-26 10:34
    关注

    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 );
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog