Vážený kolegovia, už pár dní sa zaoberam PHP frameworkom CodeIgniter. Učím sa z Yablkových tutoriálov na zajtra.sk , ktoré sú však 2 roky staré a tým si musím niektoré veci vyhľadávať v USerGuide. Avšak mám problém, keď odošlem formulár tak mi napíše:
A Database Error Occurred
You must use the "set" method to update an entry.
Filename: C:\Program Files (x86)\EasyPHP-5.4.0RC4\www\codeigniter\system\database\DB_active_rec.php
Line Number: 1174
Moje zdrojové kódy:
controler
<?php if ( !defined ('BASEPATH')) exit ('No direct script access allowed');
class Notes extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('notes_model');
$this->load->helper('form');
$this->load->helper('url');
$this->load->helper('typography');
}
function index()
{
$data['notes'] = $this->notes_model->getNotes();
$this->load->view('notes_view', $data);
}
function add()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('text', 'Novy text', 'trim|required|xss_clean|htmlspecialchars');
if ($this->form_validation->run())
{
$data = Array (
'text' => $_POST['text'],
);
$this->notes_model->addNote('notes', $data);
redirect('notes');
}
else
{
$data['notes'] = $this->notes_model->getNotes();
$this->load->view('notes_view', $data);
}
}
}
?>
view
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://127.0.0.1:8080/codeigniter/assets/style.css">
<title>Notes</title>
</head>
<body>
<div id = "container">
<?php
echo validation_errors();
echo form_open('notes/add');
echo form_textarea('text');
echo form_submit('submit', 'pridaj');
echo form_close();
?>
<ul>
<?php foreach ($notes as $obj):?>
<li>
<small><?php $obj->time ?></small>
<?php auto_typography($obj->text) ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>
model
<?php if ( !defined ('BASEPATH')) exit ('No direct script access allowed');
class Notes_model extends CI_Model {
function getNotes()
{
$query = $this->db->order_by('time desc')->get('notes');
return $query->result();
}
function addNote ($data)
{
$this->db->insert($data);
}
}
?>
Celá app je na stiahnutie tu. Vopred ďakujem za pomoc!