cakephp 3 parameter url

妖精的绣舞 提交于 2019-12-12 02:53:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!