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
#2

Hi
where is the route /komik in your routes file ?
Reply
#3

(11-27-2020, 03:08 AM)neoneeco Wrote: Hi
where is the route /komik in your routes file ?
you mean file location?
in app/Controllers/komik
Reply
#4

in the
routes.php :

PHP Code:
$routes->get('/''pages::index');

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


add:

$routes->get('/komik/', 'komik::index');


this is the routes /komik in your routes file, the missing route (i think)
Reply
#5

(11-27-2020, 01:33 PM)neoneeco Wrote: in the
routes.php :

PHP Code:
$routes->get('/''pages::index');

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


add:

$routes->get('/komik/', 'komik::index');


this is the routes /komik in your routes file, the missing route (i think)

still not working Sad
Reply
#6

Show me, the file structure to use.
Reply
#7

(This post was last modified: 11-28-2020, 03:35 AM by InsiteFX.)

Take off all the beginning / slashes and it should work.

PHP Code:
$routes->get('/''pages::index');

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

Also your controller name should be capitalized,'Komik::index' .

PHP Code:
// class name must have the first letter capitalized
class Komik extends BaseController 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(11-28-2020, 03:31 AM)InsiteFX Wrote: Take off all the beginning / slashes and it should work.

PHP Code:
$routes->get('/''pages::index');

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

Also your controller name should be capitalized,'Komik::index' .

PHP Code:
// class name must have the first letter capitalized
class Komik extends BaseController 


still not working
Reply
#9

What if :

return redirect()->to(base_url());

return redirect()->to(base_url('komik/'));

try and see
did you try other things ?
Reply
#10

I want to see complete file structure, is possible?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB