Welcome Guest, Not a member yet? Register   Sign In
How to establish blog post id and delete?
#1

[eluser]Unknown[/eluser]
Hey Guys

I apologise for this question in advance as most of you guys probably find it insultingly obvious but I have the following code from Derek Jones 20 min Blog tutorial.

Code:
<?php

class Blog extends Controller {


    function Blog()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        
    }
    
    function index()
    {
        $data['title'] = "My Blog Title";
        $data['heading'] = "My Blog Heading";
        $data['query'] = $this->db->get('entries');        
        
        $this->load->view('blog_view', $data);
    }
    
    function comments()
    {
        $data['title'] = "My Comment Title";
        $data['heading'] = "My Comment Heading";
        $this->db->where('entry_id', $this->uri->segment(3));
        $data['query'] = $this->db->get('comments');
        
    
        $this->load->view('comment_view', $data);
    }
    
    function comment_insert()
    {
        $this->db->insert('comments', $_POST);
        
        redirect('blog/comments/'.$_POST['entry_id']);
    }
    
    function delete_post()
    {

    }

}

?>

I am trying to learn more by adding some extra functionality. As you can see I want to add a delete_post function. I am not sure how to do this however.

I have guessed that the syntax should be something like this:

Code:
function delete_post()
    {
        $this->db->where();
        $this->db->delete();
        
        redirect('blog');
    }


but I am not sure what should go inside the brackets?

If anyone could help me that would be great.

Thanks guys.

D :-)
#2

[eluser]OES[/eluser]
Ok this obviously is a simple example but it will help get you going.

You are going to need to pass the ID of the post you want deleting so this is a basic example to delete that post.

Code:
function delete_post($id)
    {
        $this->db->where('id', $id);
        $this->db->delete('mytable');
        redirect('blog');
    }

Like i said simple but I hope it helps.

It does show this in the manual.

http://ellislab.com/codeigniter/user-gui...tml#delete

Good luck and welcome to CI




Theme © iAndrew 2016 - Forum software by © MyBB