我想使用codeigniter更新数据映像

czq61nw1  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(126)

严重程度:通知
消息:正在尝试获取非对象的属性“gambar”
文件名:管理员/admin
行号:42
主计长

public function edit_carousel(){//update carousel
    $id= $this->input->post('id_carousel');
    $data = $this->modelcarousel->getDataById($id)->row();
    $gambar = './assets/foto/carousel/'.$data->gambar;

    if (is_readable($gambar) && unlink($gambar)) {
        $config['upload_path']          = './assets/foto/carousel';
        $config['allowed_types']        = 'gif|jpg|png|jpeg';
        $config['max_size']             = 2048;
        $config['max_width']            = 10000000;
        $config['max_height']           = 10000000;

      $this->load->library('upload', $config);
      $this->upload->initialize($config);  
      if (!$this->upload->do_upload('gambar')) {
          $error = array('error' => $this->upload->display_errors());
      }else{
        $gambar = $this->upload->data();

        $data = array(
                'gambar' => $gambar,
                'headline' => $this->input->post('headline'),
                'deskripsi' => $this->input->post('deskripsi'),
                'status' => $this->input->post('status'),
                'tanggal_post' => $this->input->post('tanggal_post')
            );
        $update = $this->modelcarousel->update_carousel($id,$data);
        if ($update) {
            redirect('carousel');
        }else{
            echo 'Gagal';
        }
      }
    }
}

型号

function update_carousel($id,$data){//update carausel
    $this->db->where('id_carousel',$id);
    return $this->db->update('tb_carousel',$data);
}
function getDataById($id){
    $this->db->where('id_carousel',$id);
    return $this->db->get('tb_carousel');
}

database:id_carousel标题标题桌面截图状态tanggal_post

7ivaypg9

7ivaypg91#

你可以试试这个

if (is_readable($gambar)) {
            $media_files = $gamba;
            $this->load->library('upload');

            // Get file data
            $type = explode("/", $gamba['type']);
            $cMediaType = $type[0];
            $cMediaName = $gamba['name'];
}

您的控制器代码

jei2mxaa

jei2mxaa2#

更改以下代码行:
$this->load->library('upload', $config);
到此(不发送第二个参数)
$this->load->library('upload');

相关问题