问题
I would like to know how is possible that if someone write a not existent link returns error in cakephp 3.
Example:
I have an action called test inside controller calle first.
Into my routing file I have declared language in this way inside scope
:
$lang = 'it|en';
$routes->connect('/', ['language' => 'it', 'controller' => 'Pages', 'action' => 'index', 'index'],
['language' => $lang]);
$routes->connect(
'/:language/:controller',
['action' => 'index'],
['language' => $lang]
);
$routes->connect(
'/:language/:controller/:action',
['language' => $lang]
);
So i expected that with this routing system if someone write inside the url:
`http://www.myownsite.it/languagenotexist/first/test` returns error, but take `languagenotexist` as a language but lang are only: 'it|en'.
How can I return error if the parameter language isn't it or en as I have declared in route file?
This need to work:
http://www.myownsite.it/it/first/test
Or
http://www.myownsite.it/en/first/test
This need to return error like 404 for example:
http://www.myownsite.it/languagenotexist/first/test
Or
http://www.myownsite.it/es/first/test
Because parameter language isn't it or en
Routing table:
pages:index | / | {"language":"it","controller":"Pages","action":"index","0":"index","plugin":null} |
| _controller:index | /:language/:controller | {"action":"index","plugin":null} |
| _controller:_action | /:language/:controller/:action | {"language":"it|en","action":"index","plugin":null}
来源:https://stackoverflow.com/questions/36609022/cakephp-3-parameter-url