我收到错误“网址无法匹配请求的网址”:http://domain.com/blog/entry/august/18/2016/9/6/14
我非常专注于路由以帮助清理输入。我想为每个约束“定义”可接受的输入。我认为我的错误是与约束不匹配的某种类型。这并不明显,我需要一双新鲜的眼睛:
我的路由如下:
'blog-entry' => [
'type' => 'segment',
'options' => [
'route' => '/blog/entry/[:month_reference]/[:day_reference]/[:year_reference]/[:hour_reference]/[:minute_reference]/[:second_reference]',
'constraints' => [
'month_reference' => '(january|february|march|april|may|june|july|august|september|october|november|december)',
'day_reference' => '[1-31]',
'year_reference' => '[0-9]*',
'hour_reference' => '[0-23]',
'minute_reference' => '[0-59]',
'second_reference' => '[0-9]*',
],
'defaults' => [
'controller' => 'Actsministries\Blog\Controller\Blog',
'action' => 'blogentry'
]
]
],
答案 0 :(得分:1)
这些约束是正则表达式。对于数字,您将使用[0-9]。要告诉它必须在1到2位数字之间使用{1,2}。对于恰好4(年),您将使用{4}。
'blog-entry' => [
'type' => 'segment',
'options' => [
'route' => '/blog/entry/[:month_reference]/[:day_reference]/[:year_reference]/[:hour_reference]/[:minute_reference]/[:second_reference]',
'constraints' => [
'month_reference' => '(january|february|march|april|may|june|july|august|september|october|november|december)',
'day_reference' => '[0-9]{1,2}', // Between 1 and 2 digits
'year_reference' => '[0-9]{4}', // Exactly 4 digits
'hour_reference' => '[0-9]{1,2}',
'minute_reference' => '[0-9]{1,2}',
'second_reference' => '[0-9]{1,2}',
],
'defaults' => [
'controller' => 'Actsministries\Blog\Controller\Blog',
'action' => 'blogentry'
]
]
],