can't insert data on database use ckeditor5, ckfinder and codeigniter3

56 views Asked by At

ihave some error. iam try to insert data on database use ckeditor and ckfinder. when uploading data, there is a Message: Array to string conversion.

enter image description here

This my model

 public function insert($images){
        $post = $this->input->post();
        $article = str_replace('&nbsp','',$post['article']);
        $slug = url_title($post['title'], 'dash', true);
        $data = [
            'title' => $post['title'],
            'description' => $post['description'],
            'article' => $article,
            'images' => $images,
            'category' => $post['category'],
            'slug' => $slug,
            'by' => $this->session->userdata('id')
        ];

        $this->db->insert('post',$data);
        return $this->db->affected_rows();
    }

and this my controller

 function new() 
    {
        $this->load->view('admin/post/create');

        $this->form_validation->set_rules('title', 'title', 'required');
        $this->form_validation->set_rules('description', 'description', 'required');
        $this->form_validation->set_rules('category', 'category', 'required');

        if ($this->input->method() === 'post' && $this->form_validation->run()) {
            $this->save();
        }
    }

    public function save()
    {
        // the user id contain dot, so we must remove it
        $file_name = str_replace('.','',$this->session->userdata('id'));
        $config['upload_path']          = FCPATH.'/assets/upload/';
        $config['allowed_types']        = 'gif|jpg|jpeg|png';
        $config['file_name']            = $file_name;
        $config['overwrite']            = true;
        $config['max_size']             = 3024; // 1MB
        $config['max_width']            = 1080;
        $config['max_height']           = 1080;

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload('avatar')) {
            $error = $this->upload->display_errors();
            $this->session->set_flashdata('msg',$this->alert('error','Error !!!', $error));
        } else {
            $this->session->set_flashdata('msg',$this->alert('success','Success !!!', 'success membuat post baru'));
            $images = $this->upload->data();
            $this->posts->insert($images);
        }

        redirect(base_url('admin/post'));
    }

I've tried using str_replace() but it doesn't work

1

There are 1 answers

0
George W On

One of the items in your $data array is an array on its own. To find out which one it is you can do print_r($data); Then in $data array use the relevant field from the array.