自動ロード構成に既にライブラリ site_model を自動ロードしていますが、これは私が得ているエラーです:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Site::$Site_model
Filename: controllers/site.php
Line Number: 16
Fatal error: Call to a member function add_record() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/BLOCK/application/controllers/site.php on line 16
コントローラ:
<?php
class Site extends CI_Controller {
function index(){
$this->load->view('option_view');
}
function create(){
$data = array(
'subject' => $this->input->post('subject'),
'body' => $this->input->post('body')
);
$this->Site_model->add_record($data);
$this->index();
}
}
?>
モデル:
<?php
class Site_model extends CI_Model {
function get_records()
{
$query = $this->db->get('items');
return $query->result();
}
function add_record()
{
$this->db->insert('items', $data);
$return;
}
function update_record()
{
$this->db->where('id', 1);
$this->db->update('items', $data);
}
function delete_record()
{
$this->db->where('id', $this->url->segment(3));
$this->db->delete('items');
}
}
?>
とビュー:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>option_view</title>
<style type="text/css" media="screen">
label {display:block;}
</style>
</head>
<body>
<h2>Create</h2>
<?php echo form_open('site/create'); ?>
<p>
</label for="subject">Subject</label>
<input type="text" name="subject" id="subject">
</p>
<p>
</label for="body">Body</label>
<input type="text" name="body" id="body">
</p>
<p>
<input type="submit" value="Submit">
</p>
<?php echo form_close();?>
</body>
</html>
皆さんはどう思いますか?
とても有難い