0

我已经向文章页面添加了一个删除链接,但是当我单击删除时,在 URL 中它说 ..........index.php/news/delet1 它选择了 id 但出现了 404错误。

控制器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');
    }
}

视图.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';

帮助将不胜感激。

4

1 回答 1

0

您的链接似乎缺少用于传递 ID 的正斜杠。它应该是:

<p><a href="news/delete/<?php echo $news_item['id'] ?>">delete article</a></p>

于 2013-03-09T20:35:41.913 回答