[eluser]Mr. Gibon[/eluser]
Hi!
I'm developing site, and have troubles with records update, in ci.
this is my code:
model
Code:
class Shop_model extends Model {
function get_records()
{
$query = $this->db->get('table');
return $query->result();
}
function add_record($data)
{
$this->db->insert('table',$data);
return;
}
function update_record($data)
{
$this->db->where('id', $id);
$this->db->update('table',$data);
return;
}
function delete_row()
{
$this->db->where('id', $this->uri->segment(3));
$this->db->delete('table');
}
}
controller:
Code:
class Shop extends Controller {
function index()
{
$data = array();
if($query = $this->shop_model->get_records())
{
$data['records'] = $query;
}
$data['title'] = 'Szop!';
$this->parser->parse('shop_view', $data);
}
function create()
{
$data = array(
'nazwa' => $this->input->post('nazwa'),
'klasa' => $this->input->post('klasa')
);
$this->shop_model->add_record($data);
$this->index();
}
function update()
{
$data = array(
'id' => $this->input->post('id'),
'nazwa' => $this->input->post('nazwa'),
'klasa' => $this->input->post('klasa')
);
$this->shop_model->update_record($data);
}
function delete()
{
$this->shop_model->delete_row();
$this->index();
}
}
and view:
Code:
<h2>Create</h2>
<?php echo form_open('shop/create');?>
<p>
<label for="nazwa">nazwa:</label>
<input type="text" name="nazwa" id="nazwa" />
</p>
<p>
<label for="klasa">klasa:</label>
<select name="klasa"><option>1</option><option>2</option><option>3</option>
(...)</select>
</p>
<p>
<input type="submit" value="Submit" />
</p>
<?php echo form_close(); ?>
<hr />
<h2>update</h2>
<?php echo form_open('shop/update');?>
<p><label for="nazwa">nazwa:</label>
<input type="text" name="nazwa" id="nazwa" /></p>
<p><label for="id">id:</label>
<input type="text" name="id" id="id" /></p>
<p>
<label for="klasa">klasa:</label>
<select name="klasa"><option>1</option><option>2</option><option>3</option>
(...)</select>
</p>
<p><input type="submit" value="Submit" /></p>
<?php echo form_close(); ?>
<h2>Read</h2>
<?php if(isset($records)) : foreach($records as $row) : ?>
<h2>delete: <?php echo anchor("shop/delete/$row->id", $row->nazwa); ?> </h2>
<div><?php echo $row->klasa; ?></div>
<?php endforeach; ?>
<?php else : ?>
<h2>No records were returned.</h2>
<?php endif; ?>
after filling up update form, got error:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: id
Filename: models/shop_model.php
Line Number: 21
How to make it cooperate

?
Thanks for help!