Welcome Guest, Not a member yet? Register   Sign In
Need help with my delete button
#4

You can use the ID of the news item. I am assuming the ID field here is simply "id".

PHP Code:
// your view


<h2><?= esc($news['title']) ?></h2>
<p><?= esc($news['body']) ?></p>

<a href="<?= '/news/delete/' esc($news['id']) ?>">Delete</a>


// in your controller's delete method
public function delete($id)
{
    $model = new NewsModel();
    $model->where('id', (int) $id)->delete();

    return view('news/delete');


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.
Reply


Messages In This Thread
Need help with my delete button - by sheldon - 03-31-2021, 01:26 AM
RE: Need help with my delete button - by sheldon - 03-31-2021, 05:55 AM
RE: Need help with my delete button - by paulbalandan - 03-31-2021, 07:47 AM
RE: Need help with my delete button - by sheldon - 03-31-2021, 08:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB