[eluser]opel[/eluser]
Please could anyone tell me if it is possible or how to prefill a form view with data from my model and controller ?
What I have at the moment is :
Model :
Code:
function get($table, $id)
{
$query = $this->db->query("SELECT * FROM $table WHERE $id");
$result = $query->row();
var_dump($result);
}
Controller :
Code:
function edit($id){
$data['pagetitle'] = 'Edit';
//Select data based on ID
$data['body'] = $this->Pages_model->Get('pages', $id);
//write out data
$this->template->write_view('content', 'pages/page_add', $data);
//render
$this->template->render();
}
View :
Code:
<h1><?= $pagetitle; ?></h1>
<?php
$id = $this->uri->segment(3);
if($id == NULL){
$id = 'X';
}
$form = array('name'=>'text','rows' => '10', 'cols' => '30');
$attributes = array('class' => 'email', 'id' => 'myform');
echo form_open('pages/form', $attributes); ?>
<?php echo $this->validation->error_string; ?>
<table>
<tr>
<td><label><div align="right">Title : </div></label></td>
<td><?= form_input('title'); ?></p></td>
</tr>
<tr>
<td><label>Message : </label></td>
<td colspan="2"><?= form_textarea($form); ?></p></td>
</tr>
<tr>
<td><label><div align="right">Order : </div></label></td>
<td><?= form_input('order'); ?></p></td>
</tr>
<tr>
<td> </td>
<td><?= form_submit('submit', 'Add Page') ?></td>
</tr>
<tr>
<td> </td>
<td><?= form_hidden('id', $id) ?></td>
</tr>
</table>
<? echo form_close(); ?>