CodeIgniter 不喜欢博客中帖子的特殊字符段

CodeIgniter does not like special charecter slug for posts in a blog

我正在使用 CodeIgiter 框架制作一个简单的博客。我可以创建 posts,当创建 post 时,slug 将保存在数据库中。 slug 与 post 的标题相同,但如果 post 是特殊字符怎么办?例如 post 的标题是“Ķas-noķika”,当我按下阅读更多时,link 向我显示了这样的 slug - http://localhost/CodeIgniteBlog/posts/Ķas-noķika。在数据库中,slug 与 link 中的相同,但它不获取 post 而是显示 404 消息。所以我正在考虑将 url slug 从 Ķas-noķika 转换为 Kas-nokika,希望它能起作用。我如何在 CodeIgniter 中做这样的事情?我是否必须更改 config.php 或添加功能?

这里是创建 post 的函数:

public function create_post(){
        $slug = url_title($this->input->post('title'));

        $data = array(
            'title' => $this->input->post('title'),
            'slug' => $slug,
            'body' => $this->input->post('body')
        );

        return $this->db->insert('posts', $data);
    }

使用 convert_accented_characters() ,但首先你需要加载 "text" 助手。
这是一个例子:

    echo convert_accented_characters("Ķas-noķika"); //Output Kas-nokika

更多信息可以参考文档link: https://www.codeigniter.com/user_guide/helpers/text_helper.html#convert_accented_characters

转到config/config。php

查找并更新

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