自定义 url 处理程序在正确操作仍在处理时返回 404
Custom url handler returning 404 when still being handled by correct action
我有一个操作 details
正在处理 URLs:
something/details/Location/6
这很好用。不过我想把额外的细节放在最后,主要是为了SEO。
我的 routes.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
它 returns 一个 404,即使动作仍在加载并返回自身一个 renderWith()
我怎样才能让它工作? ID后面的细节我也不关心
我觉得你最后可以多加一个参数
---
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/
我有一个操作 details
正在处理 URLs:
something/details/Location/6
这很好用。不过我想把额外的细节放在最后,主要是为了SEO。
我的 routes.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
它 returns 一个 404,即使动作仍在加载并返回自身一个 renderWith()
我怎样才能让它工作? ID后面的细节我也不关心
我觉得你最后可以多加一个参数
---
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/