alexlancer / Auto-CRUD-Generator-CodeIgniter-4-

MIT License
69 stars 36 forks source link

Delete button on listing pages #6

Open zbahadir opened 3 years ago

zbahadir commented 3 years ago

I think you need a delete button in the listing pages. I myself added it to the crud_core file.

Line: 1168

Change this line: $table .= '<td class="text-center"><a href="' . $this->base . '/' . $this->table . '/edit/' . $item->{$primary_key} . '" class="btn btn-success btn-sm">Edit</a></td>';

To: $table .= '<td class="text-center"><a href="' . $this->base . '/' . $this->table . '/edit/' . $item->{$primary_key} . '" class="btn btn-success btn-sm">Edit</a>'; $table .= '<a onclick="return confirm(\'Are you sure you want to delete this record?\')" class="btn btn-danger btn-sm ml-2" href="' . $this->base . '/' . $this->table . '/delete/' . $item->{$primary_key} . '">Delete</a>'; $table .= '</td>';

I wanted to add for those who want to do.

zbahadir commented 3 years ago

I added deleteItem() function to CrudModel public function deleteItem($table, $where) { return $this->db->delete($table) ->where($where) ->get() ->getRow(); }

My delete controller: public function delete($id) { $cat = $this->crud->getItem('blogscategories', ['cat_id'=>$id]); if(empty($cat)){ $this->crud->flash('warning', 'Record is not found'); return redirect()->to('/blogscategories'); } else { $this->crud->deleteItem('blogscategories', ['cat_id'=>$id]); $this->crud->flash('success', 'Recod was deleted'); return redirect()->to('/blogscategories'); } }