Codeigniter 3应用程序错误:如果标题中有变音符号,则无法将标题转换为子弹

问题描述 投票:1回答:1

我正在使用Codeigniter 3.1.8Bootstrap 4开发基本的博客应用程序。

单个帖子的URL由带有url_title($this->input->post('title'), 'dash', TRUE)的帖子标题构成。整个后寄信功能是这样的:

public function create() {

    // Only logged in users can create posts
    if (!$this->session->userdata('is_logged_in')) {
        redirect('login');
    }

    $data = $this->get_data();
    $data['tagline'] = "Add New Post";

    if ($data['categories']) {
        foreach ($data['categories'] as &$category) {
            $category->posts_count = $this->Posts_model->count_posts_in_category($category->id);
        }
    }

    $this->form_validation->set_rules('title', 'Title', 'required');
    $this->form_validation->set_rules('desc', 'Short description', 'required');
    $this->form_validation->set_rules('body', 'Body', 'required');
    $this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');

    if($this->form_validation->run() === FALSE){
        $this->load->view('partials/header', $data);
        $this->load->view('dashboard/create-post');
        $this->load->view('partials/footer');
    } else {
        // Create slug (from title)
        $slug = url_title($this->input->post('title'), 'dash', TRUE);
        $slugcount = $this->Posts_model->slug_count($slug, null);
        if ($slugcount > 0) {
            $slug = $slug."-".$slugcount;
        }

        // Upload image
        $config['upload_path'] = './assets/img/posts';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['max_size'] = '2048';

        $this->load->library('upload', $config);

        if(!$this->upload->do_upload()){
            $errors = array('error' => $this->upload->display_errors());
            $post_image = 'default.jpg';
        } else {
            $data = array('upload_data' => $this->upload->data());
            $post_image = $_FILES['userfile']['name'];
        }

        $this->Posts_model->create_post($post_image, $slug);
        $this->session->set_flashdata('post_created', 'Your post has been created');
        redirect('/');
    }
}

我坚信它可以正常工作,直到我添加了一个标题中带有变音符号的帖子。 “ La mulți aniRomânia!”会导致<< la-mul ?? i-ani-rom ?? nia>,而不是la-multi-ani-romania我试图通过Codeigniter的convert_accented_characters()解决所有问题:

$slug = convert_accented_characters(url_title($this->input->post('title'), 'dash', TRUE));

即使您

did

加载测试助手,它也不会起作用[]:$autoload['helper'] = array('url', 'form', 'date', 'text'); 我还有哪些其他选择?如何解决此问题?
我正在使用Codeigniter 3.1.8和Bootstrap 4开发基本的博客应用程序。单个帖子的URL由帖子的标题制成,并带有url_title($ this-> input-> post('title'),'dash',真正)。 ...
codeigniter diacritics
1个回答
0
投票
这是

正确

© www.soinside.com 2019 - 2024. All rights reserved.