消息:未定义的变量:data - CodeIgniter [英] Message: Undefined variable: data - CodeIgniter
本文介绍了消息:未定义的变量:data - CodeIgniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码,我不知道我做错了,数据被定义,尽可能看到,这些是我得到的错误:
Hi guys I have this code and I am not sure what I am doing wrong, data is being defined as far as I can see, these are the errors I am getting:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: models/site_model.php
Line Number: 14
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/BLOCK/system/core/Exceptions.php:185)
Filename: core/Common.php
Line Number: 442
A Database Error Occurred
You must use the "set" method to update an entry.
Filename: /Applications/XAMPP/xamppfiles/htdocs/BLOCK/models/site_model.php
Line Number: 14
控制器:
<?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>
你们估计什么?
非常感谢。
推荐答案
模型中的方法不需要参数。例如:
The method in your models aren't expecting a parameter. For example:
更改:
function add_record()
到:
function add_record($data)
这篇关于消息:未定义的变量:data - CodeIgniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文