![]() |
I need help with this issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: I need help with this issue (/showthread.php?tid=82398) |
I need help with this issue - TheBigJae - 07-06-2022 Creating an update function on my personal project would be glad if anyone can help. This is the controller public function update($id){ helper(['form']); $model = new BlogModel(); $data = $model->find($id); //echo $data['image']; if ($this->request->getMethod() == 'post') { $rules = [ 'image' => 'is_image[image]', 'title' => 'required|min_length[3]|max_length[255]', 'body' => 'required', ]; $old_img = $data['image']; $file=$this->request->getFile('image'); if ( $this->validate($rules)) { if($file->isValid() && !$file->hasMoved()) { if(file_exists("uploads/images/".$old_img)){ \unlink("uploads/images/".$old_img); } $imagename = $file->getRandomname(); $file->move('./uploads/images/', $imagename); } else{ $imagename = $old_img; } $newData = [ 'title' => $this->request->getVar('title'), 'body' => $this->request->getVar('body'), 'slug' => url_title($this->request->getVar('title')), 'image' => $imagename ]; $model->update($id,$newData); $session = \Config\Services::session(); $session->setFlashdata('success','Post was created Successfully'); return redirect()->to('/'); }else{ $data['validation'] = $this->validator; } } RE: I need help with this issue - kenjis - 07-09-2022 What's your issue? Please don't paste code as an image file. I can't read it, it is too small, and it is difficult to run. RE: I need help with this issue - TheBigJae - 07-10-2022 Thanks Would try not to |