Welcome Guest, Not a member yet? Register   Sign In
Having problems with creating a CRUD..
#16

[eluser]Pascal Kriete[/eluser]
[ code ] tags encourage more meaningful replies.
There is a really easy solution to this. Here's the general idea.

Controller:
Code:
function edit($id)
{
    $this->load->helper('form');
    $this->load->model('comments');

    // Grab the comment with $id from the db
    $data['c'] = $this->comments->get_comment($id);

    // Validation Rules
    $rules['comment']    =>    'trim|required';
    $this->validation->set_rules($rules);
    
    // Validation Fields
    $fields['comment'] = 'Comment';
    $this->validation->set_fields($fields);
    
    // Fire
    if ( $this->validation->run() == FALSE )
    {
        // Show it
        $this->load->view('comments/edit', $data);
    }
    else
    {
        // Form posted & no errors - update
        $this->comments->update($id);
        $this->session->set_flashdata('msg', 'Comment Updated');
        redirect('');
    }
}

View:
Code:
<?=form_open('comment/edit/'.$c->comment_id)?>

<textarea name="comment" rows="8" cols="40"><?=($this->validation->comment) ? $this->validation->comment : $c->comment?></textarea>

<?=form_close()?>

And the update function of the model - I trust you can do the get part.

Model:
Code:
function update($id)
{    
    $fields['comment_body'] = $this->input->post('comment');
    
    $this->db->set($fields);
    $this->db->where('comment_id', $id);
    $this->db->update('comment_table');
}

If you want something more in depth - http://ellislab.com/forums/viewthread/81725/]request it Wink .


Messages In This Thread
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 12:03 PM
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 12:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 05:14 PM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:26 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:34 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:38 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:46 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 12:01 PM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 12:16 PM
Having problems with creating a CRUD.. - by El Forum - 06-07-2008, 01:58 AM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 12:45 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 01:01 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 02:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 02:54 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 03:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 03:47 PM
Having problems with creating a CRUD.. - by El Forum - 06-11-2008, 04:50 PM
Having problems with creating a CRUD.. - by El Forum - 06-11-2008, 05:57 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 10:09 AM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 12:33 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 02:52 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 08:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB