无法使用ckeditor5、ckfinder和codeigniter3在数据库中插入数据

gxwragnw  于 2023-08-01  发布在  其他
关注(0)|答案(1)|浏览(103)

我有一些错误。iam尝试使用ckeditor和ckfinder在数据库中插入数据。上传数据时,有一条消息:数组到字符串的转换。


的数据
这是我的模特

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();
    }

字符串
这是我的控制器

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'));
    }


我试过使用str_replace(),但它不起作用

ezykj2lf

ezykj2lf1#

$data数组中的一项本身就是一个数组。要找出它是哪一个,可以执行print_r($data);然后在$data数组中使用数组中的相关字段。

相关问题