Cakephp 3.0 - 在 MissingRouteException 的情况下执行 AppController::beforeFilter()

Cakephp 3.0 - executing AppController::beforeFilter() in case of MissingRouteException

在我的应用程序中,我根据存储在 cookie 中的用户首选项(如果有的话)或使用他的浏览器设置来定义(除其他事项外)区域设置。所有这些都在 AppController::beforeFilter().

中完成

问题:对于丢失路由异常抛出的 404 错误,请求没有到达控制器。所以我的 error400.ctp 模板没有使用正确的语言环境呈现。

因此,在 AppController::beforeFilter 中定义语言环境可能不是最佳做法。知道我应该在哪里做这个吗?

我会把逻辑放在 DispatcherFilter:

http://book.cakephp.org/3.0/en/development/dispatch-filters.html

你可以看看这个来寻找灵感:

https://github.com/cakephp/cakephp/blob/master/src/Routing/Filter/LocaleSelectorFilter.php