使用codeigniter 3建立了一个功能,可以通过子弹查看博客文章,以显示缩略图中的全文。
我在博客上单击的所有内容均出现404错误,已经检查了路线,拼写和表格,仍然出现相同的错误。
该子弹是由url_title函数制成的。
我已经没有想法了。
路线:(我已将其从顶部移至底部)
$route['Content/(:any)'] = 'Content/blogview/$1';
功能:(删除了404还是同样的问题)
public function blogview($slug=NULL) {
$data['Bpost'] = $this->Blog_Model->get_bposts($slug);
if(empty($data['Bposts'])){
show_404();
}
$this->load->view('templates/header');
$this->load->view('blogfull',$data);
$this->load->view('templates/footer');
}
型号:
public function get_bposts($slug = FALSE) {
if($slug === FALSE){
$this->db->order_by('date','DESC');
$query = $this->db->get('blogposts');
return $query->result_array();
}
$query = $this->db->get_where('blogposts',array('slug'=>$slug));
return $query->row_array();
}
如果需要,这是我的htaccess。
RewriteEngine On
RewriteBase /main
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
我将猜测这将是路线问题。我在另一个网站上具有相同的功能,并且效果很好。我真的没有关于可能的想法。
博客功能,在表格中显示一个加载缩略图的帖子,我使用foreach()遍历它们。
public function blogging() {
$data['Bposts'] = $this->Blog_Model->get_bposts();
$this->load->view('templates/header');
$this->load->view('blogging',$data);
$this->load->view('templates/footer');
}
更新以获取更多信息:
这些都是我的所有路线:
$route['Content/blogging'] = 'Content/blogging';
$route['Content/bloggingposts'] = 'Content/bloggingposts';
$route['Content/(:any)'] = 'Content/blogview/$1';
$route['Content/mail'] = 'Content/mail';
$route['Content/signed'] = 'Content/signed';
$route['Content/contactme'] = 'Content/contactme';
$route['Content/contact'] = 'Content/contact';
$route['Content/adminview']='Content/adminview';
$route['Content/blogpost']='Content/blogpost';
$route['Content/(:any)'] = 'Content/fullview/$1';
控制器中的所有博客功能:
public function blogging(){
$data['Bposts'] = $this->Blog_Model->get_bposts();
$this->load->view('templates/header');
$this->load->view('blogging',$data);
$this->load->view('templates/footer');
}
public function blogview($slug=NULL) {
$data = array();
$data['Bpost'] = $this->Blog_Model->get_bposts($slug);
$this->load->view('templates/header');
$data['view'] = 'blogfull';
$this->load->view('templates/footer');
}
public function bloggingposts(){
$data['title']= "Admin Area";
$title=$this->input->post('title');
$slug = url_title($title, 'dash', true);
$this->form_validation->set_rules('title','Title',array('required', 'min_length[1]'));
if($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header');
$this->load->view('adminblogging',$data);
$this->load->view('templates/footer');
} else {
$image = "";
if($_FILES['userfile']['name'] != "")
{
if($_FILES['userfile']['type'] == 'image/jpeg'){
$ext = ".jpeg";
} else if($_FILES['userfile']['type'] == 'image/png'){
$ext = ".png";
}
$image = time();
$config = array(
'file_name' => $image,
'upload_path' => "assets/blogimg/",
'allowed_types' => "jpg|png|jpeg",
);
$this->upload->initialize($config);
if(!$this->upload->do_upload('userfile')){
$this->session->set_flashdata( 'error_msg', $this->upload->display_errors());
redirect('Content/adminview');
}
else {
$this->Blog_Model->bposting($image,$slug);
$image = "assets/blogimg/".$image;
}
} else {
$this->Blog_Model->bposting($image,$slug);
}
$this->session->set_flashdata('post_created','Your Post has been submitted');
redirect('Content/blogging');
}
}
博客功能模型:
public function get_bposts($slug = FALSE){
if($slug === FALSE){
$this->db->order_by('date','DESC');
$query = $this->db->get('blogposts');
return $query->result_array();
}
$query = $this->db->get_where('blogposts',array('slug'=>$slug));
return $query->row_array();
}
public function bposting($image,$slug){
$data = array(
'slug'=>$slug,
'the_image' => $image,
'title'=>$this->input->post('title'),
'body'=> $this->input->post('body'),
);
return $this->db->insert('blogposts',$data);
}
答案 0 :(得分:0)
尝试一下:希望对您有帮助
public function blogview($slug=NULL) {
$data = array();
$data['Bpost'] = $this->Blog_Model->get_bposts($slug);
if(empty($data['Bposts'])){
show_404();
}
$this->load->view('templates/header');
$data['view'] = 'blogfull';
$this->load->view('templates/footer');
}