Slim framework - cannot interpret routes with dot

后端 未结 4 911
离开以前
离开以前 2020-12-19 13:46

Problem Statement

I\'m currently working on an internal RESTful API, and I\'m using our main domain name as an environment identifier. However, I noticed that Slim

4条回答
  •  轮回少年
    2020-12-19 14:10

    I would give a try to slim's Route Conditions. You should be able to specify something like this to allow dots in your parameter:

    $app->get('/:domain/:id', function($domain, $id) {
        echo $domain . ' ' . $id;
    })->conditions(array('domain' => '[a-zA-Z\.]+'));
    

    If this does not work, you should think on using another character instead of a dot to separate the domain name from the TLD and then replace it in the function:

    $app->get('/:domain/:id', function($domain, $id) {
        $domain = str_replace('_', '.', $domain);
        echo $domain . ' ' . $id;
    })->conditions(array('domain' => '[a-zA-Z_]+'));
    

    It is not so elegant, but it works.

提交回复
热议问题