Need help with my delete button |
im trying to delete a post
here is my code controler Code: <?php model PHP Code: <?php Code: <h2><?=esc($news['title'])?></h2> Code: $model->where('id',1 )->delete(); i have tried passing in id Code: public function delete($id) sorry for my bad English
Hi
The code you have written is basically the start of a CRUD type project. CRUD stands for Create, Read (view), Update and Delete. It is a standard layout for many applications. Lookup "CodeIgniter 4 CRUD" on the internet and you will find complete examples. Your controller delete($id) function has an $id parameter but when you call this delete fron your view you do not pass the id. <a href="/news/delete" class="btn btn-danger">Delete</a> should be <a href="/news/delete/$id" class="btn btn-danger">Delete</a> but I don't think you have passed any ids to the view. So check out the internet examples as mentioned above. (03-31-2021, 05:34 AM)[email protected] Wrote: Hi
You can use the ID of the news item. I am assuming the ID field here is simply "id".
PHP Code: // your view A little comment if you don't mind. I'm also assuming this delete button is only within the reach of the admins. If you release this to unprivileged users, all posts are at risk to be deleted. paulbalandanThank you so much this is what worked for me becuase i did figure out if you echo news['id Wrote:it gives the id but i did not know how to to get it in my controller THANKS pid='385678' dateline='1617202077']could you please explain to me what i did wrong and also thank you for the comment you made i will keep that in mind |
Welcome Guest, Not a member yet? Register Sign In |