代码之家  ›  专栏  ›  技术社区  ›  se_pavel

Zend框架路由模拟

  •  0
  • se_pavel  · 技术社区  · 15 年前

    这是Rails 3代码

    匹配“/文章(/:年(/:月(/:日))”=>“文章\索引”

    匹配的URL,其中某些部分可以省略以发布控制器和索引操作

    在Zend框架中,最优雅的方法是什么

    1 回复  |  直到 15 年前
        1
  •  1
  •   Keeper    15 年前

    我认为这条路线应该足够了:

    $route = new Zend_Controller_Router_Route(
        'articles/:year/:month/:day',
        array(
            'year'       => date("Y"),
            'month'      => date("m"),
            'day'        => date("d"),
            'controller' => 'post',
            'action'     => 'index'
        ),
        array(
            'year' => '\d+',
            'month' => '\d+',
            'day' => '\d+',
        )
    );
    

    默认为当前日期/月/年