[eluser]cvandal[/eluser]
OK,
I've created a new view with a separate form for updating. I've used the form helper to select what information is loaded into the form when you click on the 'Update' link.
When the page loads, I get 2 errors, 'Undefined variable: title' and 'Undefined variable: content'.
I thought the variables would be loaded by these functions in my controller when it performs a query:
Code:
function update()
{
$data = array();
if($query = $this->crud_model->get_entry())
{
$data['pages'] = $query;
}
$this->load->view('update_view', $data);
}
function update_page()
{
$data = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content')
);
$this->crud_model->update_entry($data);
redirect('');
}
The Model:
Code:
function update_entry($data)
{
$this->db->update('pages', $data);
return $data->row();
}
The view which contains the option to update:
Code:
<p><?=anchor("crud/update/$row->id", 'Update'); ?></p>
The view which contains the form which should be automatically populated when the user clicks on the 'Update' link in the previouse view:
Code:
<?=form_open('crud/update_page') ?>
<p>
<label for="title">Title:</label>
<input type="text" name="title" id="title" value="<?=$title?>" />
</p>
<p>
<label for="content">Content:</label>
<textarea name="content" id="content"><?=$content?></textarea>
</p>
<p>
<input type="submit" value="Update" />
</p>
</form>