Case Insensitive Routing in CodeIgniter

前端 未结 8 953
南笙
南笙 2021-01-13 21:46

I\'ve written this in the CodeIgniter\'s routers.

$route[\'companyname\'] = \"/profile/1\";

This is working fine but when I type \"CompanyN

8条回答
  •  被撕碎了的回忆
    2021-01-13 22:23

    If you want case-insensitive routing for all routes, you just need to extend CI_Router class, then modify _parse_routes() method like this:

    public function _parse_routes()
    {
        foreach ($this->uri->segments as &$segment)
        {
            $segment = strtolower($segment);
        }
    
        return parent::_parse_routes();
    }
    

    It will be cleaner than editing the CI_URI class itself. :)

提交回复
热议问题