CodeIgniter URI中不允许使用句点


Periods not allowed in CodeIgniter URI?

因此,在阅读了关于API版本控制的问题后,我决定在所有路由前面加上一个版本号:

http://localhost/api/1.0/user/login

但当我在Exceptions Core中抛出一个异常时,它会说路径是:

10/UserControll...

我试过逃离那段时期,但没有成功。有人能复制这个问题并想出可能的解决方案吗?

这是我在上面使用的路线:

$route['1.0/user/(:any)'] = '1.0/UserController/$1';

这些是我允许的URI字符:

$config['permitted_uri_chars'] = 'a-z 0-9~%'.:_'-';
Open libraries/Input.php (system/core/Input.php in CI version 2.0+) and locate function _clean_input_keys($str){, The whole block should look like so:
function _clean_input_keys($str)
{
    if ( ! preg_match("/^[a-z0-9:_'/-]+$/i", $str))
    {
        exit('Disallowed Key Characters.');
    }
    return $str;
}

检查是否有"。"在preg_match中。如果不添加它,使您的正则表达式看起来像这样-

/^[a-z0-9:_'/-'.]+$/i

中有(.)吗

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_'-';

您的控制器名称是什么?

我认为您的路由中的控制器名称必须在方法名称之前。

类似这样的东西:

$route['controller_name/1.0/user/(:any)'] = ...

问题出现在system/core/Router.php的第468行。将set_directory从此更改为:

$this->directory = str_replace(array('/', '.'), '', $dir).'/';

对此:

$this->directory = str_replace(array('/'), '', $dir).'/';

有人想知道为什么路由器会从目录名中删除句点吗?