自定义网址处理程序仍在通过正确的操作进行处理时返回404

时间:2018-08-15 00:43:59

标签: php routing silverstripe

我有一个处理URL的操作details

something/details/Location/6

,这很好。但是,我想在结尾处添加更多细节,基本上是针对SEO。

我的路线上有。yml:

---
Name: mysiteroutes
---
Director:
  rules:
    'something//$Action/$Location/$OtherID': 'SomeController'

以及在我的控制器中:

private static $url_handlers = array(
    'something//$Action/$Location/$OtherID' => 'handleAction'
);

如果我转到上面的URL,它会起作用,但是,如果我转到something/details/Location/6/test,它会返回404,即使该操作仍在加载并返回renderWith()

我该如何使用它?我也不在乎ID后的详细信息。

1 个答案:

答案 0 :(得分:2)

我认为您最终可以添加更多参数

---
Name: mysiteroutes
---
Director:
  rules:
    'something': 'SomeController'

和您的控制器

private static $allowed_actions = array('details');
private static $url_handlers = array(
    'details/$Location/$OtherID/$otherParam' => 'details'
);
public function details() {
    $this->getRequest()->param('otherParam');
    /* more processing goes here */
}

更多信息 https://docs.silverstripe.org/en/3/developer_guides/controllers/routing/