【问题标题】:codeigniter, error Message: Creating default object from empty valuecodeigniter,错误消息:从空值创建默认对象
【发布时间】:2015-02-10 17:51:01
【问题描述】:

严重性:警告 消息:从空值创建默认对象 文件名:控制器/person.php 行号:133

   function update($id)
        {
            $responce = new StdClass;
            $this->_set_rules();
            $person = $this->Person_model->get_by_id($id)->row();

error in this line i  try to figure it ot
           $this->form_data->id = $id; 


            $this->form_data->name = $person->name;
            $this->form_data->gender = strtoupper($person->gender);
            $this->form_data->dob = date('d-m-Y',strtotime($person->dob));


            $data['title'] = 'Update person';
            $data['message'] = '';
            $data['action'] = site_url('person/updatePerson');
            $data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));

            // load view
            $this->load->view('personEdit', $data);
        }

【问题讨论】:

  • 从空值创建默认对象
  • 如果您喜欢我的回答,请考虑“投票”
  • form_data 来自哪里?我看到您正在从 Person_model 获取数据并将结果行保存到变量 $person...但我看不到您在哪里声明 form_data(至少在此函数中)

标签: codeigniter stdclass


【解决方案1】:

stdClass 中的小写“s”:

$response = new stdClass;

不是:

$responce = new StdClass;

在此处了解有关 PHP 对象的更多信息: http://php.net/manual/de/language.types.object.php

【讨论】:

  • 请注意。响应拼写为“s”,而不是“c”(无论您来自英国还是美国)。所以最好的答案是$response = new StdClass;
【解决方案2】:

您需要创建如下所示的数据对象。

$responce = new stdClass();

希望这能解决您的错误。

【讨论】:

    猜你喜欢
    • 2021-02-22
    • 2015-01-28
    • 2019-01-15
    • 2016-10-11
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2023-03-11
    • 2013-06-19
    相关资源
    最近更新 更多