Routing: Multiple Use of Pattern with different Methods

Hi, can it be that the following does not work?

'routes' => [
   [
      'pattern' => '(:any)',
      'language' => 'en',
      // 'method' => 'GET',
      'action'  => function ($language, $any) {
         //... some code here
      }
   ],
   [
      'pattern' => '(:any)',
      'language' => 'en',
      'method' => 'POST',
      'action'  => function () {
         //... some code here
      }
   ],
]

Do I have to write everything like this instead?

   [
      'pattern' => '(:any)',
      'language' => 'en',
      'method' => 'GET|POST',
      'action'  => function () {
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
             //... some code here
         } else {
             //... some code here
         }
      }
   ],

It is too long to describe the exact error that occurs here (among other things, it is about a uniform form with AJAX, where the error message is not translated).

Thanks,
Robert

Kirby uses the same routes with different methods as well, set up a quick test with simple routes to make sure they work in general.

Ok thanks texnixe, as soon as I have time again I will try to find out why this does not work for me.

What else I noticed:

I am working on a multilanguage site (DE|EN).
DE is the main language and is always without language code in the url.

So I noticed that in the routes the action of DE is always called, when the current language is EN.

Is this meant to be, or am I doing something wrong here too?

And one more thing I noticed when the current language is EN:

When URL looks like this : https://example.com/ en /…/…

[
         'pattern' => '(:any)',
         'language' => 'en',
         'method' => 'GET|POST',
         'action'  => function ($language, $any) {
             // $any == **en** !!!!
          .....

Is this a bug or is this the way it’s supposed to be?

If you use one language with and one without a language code, then you need separate routes or you have to use if statements inside your route to check if the variable is a language code or not.

It works better when both languages use a language code.

Ok, so I know that I am not completely wrong here.

It seems that I have to deal with the routing in more detail. Slowly, it’s all becoming clearer to me in this regard.

Thanks,
Robert