我在文章页面中添加了一个删除链接,但是当我点击删除时,在URL中它表示.......... index.php / news / delet1它会选择id但是会出现有404错误。
controller news.php
public function delete($id){
$id = $this->uri->segment(3);
$data['title'] = 'Delete an item';
if($this->news_model->delete_news($id)){
$this->load->view('templates/header', $data);
$this->load->view('news/success');
$this->load->view('templates/footer');
}
}
view.php
<p><a href="news/delete<?php echo $news_item['id'] ?>">delete article</a></p>
news_model.php
public function delete_news($id){
$this->db->where('id',$id)->delete('news');
return $this->db->affected_rows();
}
路线
$route['news/delete/(:num)'] = 'news/delete/$1';
帮助将不胜感激。
答案 0 :(得分:0)
您的链接似乎缺少正斜杠以传递ID。它应该是:
<p><a href="news/delete/<?php echo $news_item['id'] ?>">delete article</a></p>