Welcome Guest, Not a member yet? Register   Sign In
localhost send an invalid response
#1

hello there,

im just learning codeigniter 4 from youtube "web programming unpas". so im followed his course to create form with post method to insert data.
after insert the data succesfully, it will redirect to the index file. then, after i tried to insert data, the data its inserted successfully, but cannot redirect and showing error

"localhost send an invalid response"

here the code
route.php
Code:
$routes->get('/', 'pages::index');

$routes->get('/komik/create', 'komik::create');
$routes->get('/komik/(:segment)', 'komik::detail/$1');

controller/komik.php
Code:
<?php
namespace App\Controllers;

use App\Models\komikmodel;

class komik extends BaseController

    {
         protected $komikmodel;
   
         public function __construct()
         {
              $this->komikmodel = new komikmodel();
         }
   
   
         public function index()
         {
                $data = [
                   'title' => 'Daftar Komik' ,
                   'komik' => $this->komikmodel->getkomik()
              
              ];
              return view('komik/index', $data);
         }
   
         public function detail($slug)
         {
              $data = [
                   'title' => 'Detail Komik',
                   'komik' => $this->komikmodel->getkomik($slug)
              ];
   
              if(empty($data['komik']))
              {
                   throw new \CodeIgniter\Exceptions\PageNotFoundException('Judul Komik '. $slug. 'Tidak Ditemukan');
              }
   
              return view('komik/detail', $data);
         }
   
         public function create()
         {
              $data = [
                   'title' => 'Form Tambah Data Komik'
              ];
   
              return view('/komik/create', $data);
         }
   
         public function save()
         {
              $slug = url_title($this->request->getVar('judul'), '-', true);
   
              $this->komikmodel->save([
                   'judul' => $this->request->getVar('judul'),
                   'slug' => $slug,
                   'penulis' => $this->request->getVar('penulis'),
                   'penerbit' => $this->request->getVar('penerbit'),
                   'sampul' => $this->request->getVar('sampul')
              ]);
   
              session()->setFlashData('pesan', 'Data berhasil di tambahkan!');
   
              return redirect()->to('/komik');
         }
    }

any suggestion will be appreciated
thanks
Reply


Messages In This Thread
localhost send an invalid response - by upnormal - 11-26-2020, 07:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB