IM刪除在coneigniter2一排,但它需要我的404頁 (您請求未找到頁。)錯誤404笨2
這是我的代碼
的Controler郵政
class Posts extends CI_Controller{
public function index(){
$data['title'] = 'Ultimos Post';
$data['posts'] = $this->Post_model->get_posts();
$this->load->view('templates/header');
$this->load->view('posts/index',$data);
$this->load->view('templates/footer');
}
...
public function delete($id){
//apagar post pelo id
$this->Post_Model->delete_post($id);
redirect('posts');
}}
郵政型號
class Post_model extends Ci_Model{
...
public function delete_post($id) {
$this->db->where('id',$id);
$this->db->delete('posts');
}}
在View.php
<?php echo form_open('/posts/delete/'.$post['id']);?>
<input type="submit" value="Delete" class="btn btn-danger" name="delete">
routes.php文件
$route['posts/create'] = 'posts/create';
$route['posts/(:any)'] = 'posts/view/$1';
$route['posts'] = 'posts/index';
$route['default_controller'] = "pages/view";
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
刪除'$ id'爭論就這樣做解決來自c ontroller函數並使用'$ id = $ this-> uri-> segment(3);' – ImBS
我得到了同樣的錯誤,它找到了id,但是像這樣[http:// localhost/blog/posts/delete/2 ] –
請將您的'routes'配置添加到問題中。 –