我正在使用Codeigniter 3.1.8和Bootstrap 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',真正)。 ...
正确