CodeIgniter Forums
localhost send an invalid response - 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: localhost send an invalid response (/showthread.php?tid=78084)

Pages: 1 2


localhost send an invalid response - upnormal - 11-26-2020

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


RE: localhost send an invalid response - neoneeco - 11-27-2020

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


RE: localhost send an invalid response - upnormal - 11-27-2020

(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


RE: localhost send an invalid response - neoneeco - 11-27-2020

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)


RE: localhost send an invalid response - upnormal - 11-27-2020

(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


RE: localhost send an invalid response - mylastof - 11-28-2020

Show me, the file structure to use.


RE: localhost send an invalid response - InsiteFX - 11-28-2020

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 



RE: localhost send an invalid response - upnormal - 11-28-2020

(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


RE: localhost send an invalid response - neoneeco - 11-29-2020

What if :

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

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

try and see
did you try other things ?


RE: localhost send an invalid response - mylastof - 11-29-2020

I want to see complete file structure, is possible?