2015-04-04 136 views
1

当我尝试运行我的代码,我得到这样的警告:如何从空值创建默认对象?

创建默认的对象从空值(上线#24)

控制器:

public function createFields($tablename) { 
    $this->load->model(array('Connection_model', 'Read_data_model'));  
    $posts = $this->input->post(NULL, TRUE); 
    foreach ($posts as $key => $value) { 
     if (isset($value) && !empty($value) && isset($key) && !empty($key) && $key != 'submit') { 
      $this->Read_data_model->isset_row('sender', $tablename, $key);    
     } 
    } 
} 

型号:

public function isset_row($target, $table, $key) { 
    $this->load->model('Connection_model'); 
    $query = $this->Connection_model->get_custom_db('sender')->get($table); 
    foreach ($query->result() as $row->{$key}) { // This is line #24 
     echo $row->{$key}; 
    } 
} 

我在做什么错?

+0

使用StdClass作为空对象 – user1954544 2015-04-05 00:15:39

回答

1

我自己找到了解决方案。在foreach循环中,它只需要$row而不是$row->{$key}

相关问题