我只是想知道为什么我的 Codeigniter 项目会生成以下警告消息。
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: controllers/person.php
Line Number: 268
在我的人控制器中,
function __construct()
{
parent::__construct();
// load library
$this->load->library(array('table','form_validation'));
// load helper
$this->load->helper('url');
$this->load->config('array_constant', TRUE);
// load model
$this->load->model('Person_model','',TRUE);
}
// set empty default form field values
function _set_fields()
{
Line No: 268 $this->form_data->id = '';
$this->form_data->name = '';
$this->form_data->gender = '';
$this->form_data->dob = '';
$this->form_data->district = '';
$this->form_data->education = '';
$this->form_data->occupation = '';
$this->form_data->annual_income = '';
$this->form_data->company_name = '';
$this->form_data->description = '';
}
在我的视图文件中,
<table width="100%">
<tr>
<td width="30%">ID</td>
<td><input type="text" name="id" disabled="disable" class="text" value="<?php echo set_value('id'); ?>"/></td>
<input type="hidden" name="id" value="<?php echo set_value('id',$this->form_data->id); ?>"/>
</tr>
<tr>
<td valign="top">Name<span style="color:red;">*</span></td>
<td><input type="text" name="name" class="text" value="<?php echo set_value('name',$this->form_data->name); ?>"/>
<?php echo form_error('name'); ?>
</td>
</tr>
抑制上述警告的任何想法或建议!
echo "<pre>";
var_dump($this->form_data);
echo "</pre>";
object(stdClass)#21 (10) {
["id"]=>
string(0) ""
["name"]=>
string(0) ""
["gender"]=>
string(0) ""
["dob"]=>
string(0) ""
["district"]=>
string(0) ""
["education"]=>
string(0) ""
["occupation"]=>
string(0) ""
["annual_income"]=>
string(0) ""
["company_name"]=>
string(0) ""
["description"]=>
string(0) ""
}