Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter not able to instantiate controller class

Tags:

codeigniter

So I'm trying to troubleshoot why CodeIgniter won't display any output (except for 404's and such). I've checked everything from error logging in php and apache and codeigniter, to the module rewriting. Everything seems to be configured just fine.

I started to dive into the CodeIgniter core files and noticed that it was crashing on the line below that tries to instantiate the requested controller class:

        $class  = $RTR->fetch_class();
        $method = $RTR->fetch_method();

echo 'looking for class: ' . $class . '<br/>';
if(class_exists($class) == false) {

                )
        {
                echo 'class does not exist: ' . $class;
                show_404("{$class}/{$method}");
        }
}

/*
 * ------------------------------------------------------
 *  Is there a "pre_controller" hook?
 * ------------------------------------------------------
 */
        $EXT->_call_hook('pre_controller');
echo '<br/>after precontroller';
/*
 * ------------------------------------------------------
 *  Instantiate the requested controller
 * ------------------------------------------------------
 */
        // Mark a start point so we can benchmark the controller
        $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');

echo '<br/>before class init: ' . $class;
        $CI = new $class();
echo '<br/>after class init';

This is within the /core/CodeIgniter.php file. Here is the output:

CodeIgniter.php
looking for class: servicecontroller

after precontroller
before class init: servicecontroller

Basically it's telling me that it can find the servicecontroller class, but when it tries to instantiate it, it crashes. php error logging is enabled, and display_errors is on. If I force a php error anywhere near here, I see it on the page, but not this one. Does anyone have any idea why it can't get past this line?

servicecontroller.php is arranged like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class servicecontroller extends CI_Controller {
}
like image 456
Ryan Weiss Avatar asked Jun 05 '13 20:06

Ryan Weiss


1 Answers

Okay, the root of this problem was an error connecting to the database using mysql_connect. For some reason, it would not produce any error whatsoever, nor would "or die("error..."); do anything. This was because we were using php 5.4 on the server, and mysql_connect does not seem to be supported anymore, unless you have mysqlnd installed. The solution was to switch our database driver to 'mysqli', which CodeIgniter luckily has a driver for, and then install php5-mysql with: apt-get install php5-mysql Hope this helps anyone else.

like image 192
Ryan Weiss Avatar answered Sep 28 '22 01:09

Ryan Weiss