Codeigniter CRUD: Day 5 Delete Operation

Codeigniter | Crud | Mvc

Codeigniter CRUD Day 5


This entry is part 5 of 6 in the series CodeIgniter CRUD

Codeigniter CRUD: Day 5 Delete Operation: In Day 4 Update Operation we created view & updated controller for update operation to work. which is responsible for showing edit form for previously created post entry and updating it to database via post model. Now we have our create, read & update operations ready let’s move on to Delete Operation of Codeigniter CRUD. So that we can delete created posts.

Delete Operation is very easy to implement and we only need to change the post controller code. and we will done.

Controller Code for Codeigniter CRUD’s Delete Operation

Add new method in post controller. Name it delete(). Add following code for delete method in post controller.

First step is to get id from 3rd segment of URL. then pass it to post model’s delete method which we created on Codeigniter CRUD: Day 1 Create model. delete method of post model will delete record whose id matches. Next we set a flash message for successful deletion. And redirect user to post listing page. So thats it and we done with delete operation. Let’s test it.

Open Browser and navigate to  http://localhost:8888/ci/index.php/post . Click on delete link of record you want to delete. And it will be deleted. User will redirected to post listing page where he/she can see successful message for delete operation.

That’s it for Codeigniter CRUD Delete Operation. We just finished whole course of Codeigniter CRUD. Congratulations on successful completion of Codeigniter CRUD crash course. Download full source code of Codeigniter CRUD from below Link.

I have added a bonus codeigniter pagination tutorial in this course. And I highly recommend you add pagination to your website to increase performance


Download Source Code Files


Please like our Facebook Fan page for instant updates on Tutorials.

Series Navigation<< Codeigniter CRUD: Day 4 Update OperationHow to Add Codeigniter Pagination >>

Bookmark Link using: bookmark at folkd