dongzi5673 2019-04-25 07:57
浏览 92

Codeigniter:如何使用url将UTF8参数传递给控制器​​?

I'm using Code-igniter 3 and need to pass a parameter to a controller using URL parameters. My URL is something like this:

http://192.168.40.50/user/list/محمد

And I added this to the config file :

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

And my controller is like this:

public function list($name)
{ 
    // The $name parameter is incorrect here
    // In this case $name = 'E-E'
}

The problem is that I'm getting 'E-E' instead of 'محمد'.

I just search a lot of questions but didn't find a solution

َUPDATE

I'm using routing. The parameters are delivered correctly without routing but when I add routes UTF-8 characters are changed. My route is just like this:

$route['user/list/(:any)'] = 'user/list_of/$1';
  • 写回答

1条回答 默认 最新

  • doufei2328 2019-04-25 08:02
    关注

    Phil Sturgeon explains allowing UTF-8 extensively: here is an excerpt followed by the full article link:

    Set the HTTP header in index.php All requests to CodeIgniter are made through the index.php file which by default sits outside the system/ folder. For this reason it makes a perfect place to add a PHP header for me.

    header('Content-Type: text/html; charset=utf-8');
    

    Tell CodeIgniter what's going on CodeIgniter by default is set to use UTF-8 for much of its internal functionality, so just make sure the charset is set to UTF-8 in your application/config/config.php file.

    $config['charset'] = "UTF-8";
    

    Configure database connection

    $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_unicode_ci";
    

    At this point you should be able to use the UTF-8 Characters, if you want to save it into the DB which I am using you would do, read on further using this link:

    USING UTF-8

    You can also refer to this stackoverflow post: Using UTF-8 Stackoverflow

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog