1

How to fix this error? Directory -application -controller -Rest.php -app.js

app.js

'use strict';

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var phpExpress = require('php-express')({

  // assumes php is in your PATH
  binPath: 'php'
});
var path = require('path');

app.set('port',process.env.PORT || 8000);
app.set('views','application/controllers');
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');

app.use(require('express').static(path.join(__dirname, 'public')));
app.use(require('express').static(path.join(__dirname, 'bower_components')));

app.get('/', function(req, res) {
  return res.render('rest');
});

io.on('connection', function(socket) {
  socket.on('chat:pesan', function(pesan) {
    io.emit('chat:pesan', pesan);
  });
});

http.listen(app.get('port'), function() {
  console.log('Server jalan di port ' + app.get('port') + __dirname);
});

Rest.php

<?php
class Rest extends CI_Controller{
    public function __construct(){
        parent:: __construct();   
        date_default_timezone_set("Asia/Jakarta");
        $this->load->helper('url');
        $this->load->model('rest_model');
        $this->load->model('log_model');
        $this->load->library('parsing_data');
    }
}
?>

Result

Fatal error: Class 'CI_Controller' not found in C:\xampp\htdocs\iap\tugas1\application\controllers\rest.php on line 2

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
  • 2
    Have you set up autoloading of some sort? Does the file it is not seeing exist? – Bananaapple Aug 23 '17 at 10:01
  • just use autoloading or include your CI_Controller class file at the top of your Rest file like this : `include_once 'CI_Controller.php' ` – yoeunes Aug 23 '17 at 10:03
  • Why do you set views into controllers? You already have views directory for convinience and for MVC sake. Few things about Rest: Set filename with ucfirst() - meaning *R*est.php, you have to set `index()` method to be able to call that `controller/method` route, remove closing PHP tag. – Tpojka Aug 23 '17 at 16:52
  • CI_Controller is from CodeIgniter. CI_Controller should exist if the HTTP request comes in through CodeIgniter. – Brian Gottier Aug 23 '17 at 18:03
  • @Bananaapple How to set up autoloading? – Irvan Ahmad Prasetya Aug 24 '17 at 03:11
  • @yoeunes If I add the code there will be error as below Warning: include_once(CI_Controller.php): failed to open stream: No such file or directory in C:\xampp\htdocs\iap\tugas1\application\controllers\rest.php on line 2 Warning: include_once(): Failed opening 'CI_Controller.php' for inclusion (include_path='D:\xampp2\php\PEAR') in C:\xampp\htdocs\iap\tugas1\application\controllers\rest.php on line 2 – Irvan Ahmad Prasetya Aug 24 '17 at 03:13
  • @Tpojka Because I will also do the query. So I put it to the controller to connect it with view – Irvan Ahmad Prasetya Aug 24 '17 at 03:15
  • @BrianGottier So, what should I do? – Irvan Ahmad Prasetya Aug 24 '17 at 03:16
  • @IrvanAhmadPrasetya , if this is CodeIgniter 3, you need to capitalize the filename or your rest.php file. Make it Rest.php. Let me know ... – Brian Gottier Aug 24 '17 at 03:44
  • @BrianGottier still can not Error: Fatal error: Class 'CI_Controller' not found in C:\xampp\htdocs\iap\tugas1\views\application\controllers\Rest.php on line 2 – Irvan Ahmad Prasetya Aug 24 '17 at 04:17
  • https://stackoverflow.com/questions/15207937/codeigniter-command-line-error-php-fatal-error-class-ci-controller-not-foun | https://stackoverflow.com/questions/6758681/codeigniter-class-ci-controller-not-found | https://www.google.com/search?client=ubuntu&channel=fs&q=Class+%27CI_Controller%27+not+found&ie=utf-8&oe=utf-8 – Brian Gottier Aug 24 '17 at 04:24
  • @BrianGottier I've turned it into `$config['log_threshold'] = 0;` and `$route['404_override'] = 'controller/method/parameter';` But still error – Irvan Ahmad Prasetya Aug 24 '17 at 05:58
  • I guess my only advice would be to replace the /system folder with a fresh copy. I've personally had corrupt downloads do this kind of thing, so re-download CodeIgniter and swap out the folder. It's worth a shot I guess. – Brian Gottier Aug 24 '17 at 06:48
  • @BrianGottier If i use localhost then there is no error, but when i use localhost: 3000 for socket io always error – Irvan Ahmad Prasetya Aug 24 '17 at 07:14
  • Sounds like you need to tell the webserver (Apache, nginx) not to listen on that port. If you're using socket.io then you probably have it listening, right? I don't have the expertise to help you with your server configuration, but it sounds like you need that. – Brian Gottier Aug 24 '17 at 16:09
  • @BrianGottier Okay... thanks... – Irvan Ahmad Prasetya Aug 25 '17 at 06:42

0 Answers0