2016-07-05 56 views
0

非字母数字字符按照ZF2手册我应该能够使用非字母数字字符以单独的段中的路径:ZF2 - 路由,在段

zf2 manual routing

我有一个所述以下路线:

'may_terminate' => true, 
    'child_routes' => [ 
    'image' => [ 
     'type' => 'segment', 
     'options' => [ 
     'route'  => '/image/:id-:width-:height-:slug-:ext', 
     'defaults' => [ 
      'controller' => ImageController::class, 
      'action'  => 'image' 
     ] 
     ], 
    ], 
], 

在我看来,像这样的应用:

/image/1-100-100-my_image.png 

我现在面临的问题是这样的:

当我把我的路线像这样:

'route'  => '/image/:id-:width-:height-:slug-:ext', 

我收到以下错误:

The requested URL could not be matched by routing. No Exception available

如果更新我的路由器:

'route'  => '/image/:id/:width/:height/:slug/:ext', 

它按预期工作。

我使用PHP7与ZF2版〜2.3

虽然我可以用:/作为分隔符,显然是一个减号更有意义。这个问题会是什么?

回答

0

从手动

The {-} after the :foo parameter indicates a set of one or more delimiters, after which matching of the parameter itself ends.

尝试添加{-}。因为-是一个通常的符号,所以它不是分隔符。

并尝试描述路由参数。

'image' => [ 
    'options' => [ 
     'constraints' => [ 
      'id' => '[0-9]+', 
      'width' => '[0-9]+', 
      'height' => '[0-9]+', 
      'slug' => '[\w\d]+', 
      'ext' => '\.png', 
     ] 
    ] 
] 
+0

我相信这会起作用,有一些有趣的问题与骷髅翻译不喜欢大括号。这最终解决了这个符号:'route'=>'image /:id [ - ]:width [ - ]:height [ - ]:slug [。]:ext', – HappyCoder