[eluser]xeroblast[/eluser]
i think this is the line where you got it wrong:
your controller:
Code:
function update() {
$data = array(
'title' => $this->input->post('title'),
'contents' => $this->input->post('contents')
);$this->load->view('editnews', $data);
if($_POST) {
$this->admin_model->update($data);
}
if($_POST != NULL) {
redirect('../admin/');
}
}
your view:
Code:
<li>
<?= form_input('title') value ?>
</li>
<li>
<label>Content:</label>
</li>
<li>
<?= form_textarea('contents') ?>
</li>
<li>
<?= form_submit('', 'Submit') ?>
</li>
you should do it like this:
controller:
Code:
function update($id) {
// this is where if the submit button is push
if ($_POST) {
$save = array(
'title' => $this->input->post('title'),
'contents' => $this->input->post('contents'),
);
$this->admin_model->update($save,$id); // use the model i created in my previous post
}
//this is where you load the data to view
$data['blah'] = $this->admin_model->get($id);
$this->load->view('editnews',$data);
}
your view:
Code:
<?= form_open($this->uri->uri_string()) ?>
<li>
<?= form_input(array('name' => 'title', 'value' => $blah->title)) ?>
</li>
<li>
<label>Content:</label>
</li>
<li>
<?= form_textarea(array('name' => 'contents', 'value' => $blah->contents)) ?>
</li>
<li>
<?= form_submit('', 'Submit') ?>
</li>
<?= form_close() ?>
your model should have this: to get a single row data...
Code:
function get($id) {
return $this->db->get_where('table',array('id' => $id))->row();
}