Reputation: 710
In my app, I define (among other things) the locale based on user's preference stored in cookie if any, or by using his browser's settings. All of this is done in AppController::beforeFilter().
Problem: for 404 errors thrown by a missing route exception, the request doesn't event reach the controller. So my error400.ctp template is not rendered with the correct locale.
So defining the locale in AppController::beforeFilter may not be the best practice. Any idea where I should do this?
Upvotes: 1
Views: 1011
Reputation: 9614
I would put the logic in a DispatcherFilter
:
http://book.cakephp.org/3.0/en/development/dispatch-filters.html
You can take a look at this one for inspiration:
https://github.com/cakephp/cakephp/blob/master/src/Routing/Filter/LocaleSelectorFilter.php
Upvotes: 2