title: CodeIgniter Custom Library Not Loading
body: <p>I'm new to CodeIgniter and trying to developing a fairly simple application with it -- just a form to process the registration for employees wanting a recreation center pass.  I'm trying to separate things to make them cleaner. </p>
  
  <p>Here is the code:</p>
  
  <p>application/controllers/reccenter.php</p>
  
  <pre><code>class RecCenter extends CI_Controller {
  
      public function register() {
          $data['title'] = "Utah Valley Rec Center Registration";
  
          $this-&gt;output-&gt;enable_profiler(TRUE); // Put all the debug statements at the bottom of the page
          $this-&gt;load-&gt;helper('html');
  
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;form_validation-&gt;set_rules('userRecCenter', 'recreation center selection', 'required');
  
          $userRecCenter = $this-&gt;input-&gt;post('userRecCenter');
          $registerSelf = $this-&gt;input-&gt;post('registerSelf');
          $dependents = $this-&gt;input-&gt;post('dependents');
  
          if($this-&gt;input-&gt;post('registerSelf') &amp;&amp; !$registerSelf) { // Employee not registering themselves
              $this-&gt;form_validation-&gt;set_rules('dependents', 'self selection or dependents', 'required');
          } else if($this-&gt;input-&gt;post('dependents') &amp;&amp; count($dependents) == 1 &amp;&amp; $dependents[0] == "") { // Employee only registering themselves
              $this-&gt;form_validation-&gt;set_rules('registerSelf', 'self selection or dependents', 'required');
          }
  
          if ($this-&gt;form_validation-&gt;run() == FALSE) {
              $this-&gt;load-&gt;view('templates/header', $data);
              $this-&gt;load-&gt;view('pages/reccenter/register', $data);
              $this-&gt;load-&gt;view('templates/footer', $data);
          } else {
              $this-&gt;load-&gt;library('Reccenterdao');
              $numRows = $this-&gt;reccenterdao-&gt;getRecCenterInfo();
              var_dump($numRows);
  
              // Check if already registered 
                  // Redirect to different view to change their registration
  
              // Do the registration
                  //redirect('reccenter/confirm');
          }
      }
  
      public function confirm() {
          $data['title'] = "Utah Valley Rec Center Registration Confirmation";
  
          $this-&gt;load-&gt;view('templates/header', $data);
          $this-&gt;load-&gt;view('pages/reccenter/confirm', $data);
          $this-&gt;load-&gt;view('templates/footer', $data);
      }
  }
  </code></pre>
  
  <p>application/libraries/Reccenterdao.php</p>
  
  <pre><code>if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
  
  class Reccenterdao {
  
      private $CI;
  
      public function __construct() { 
          $this-&gt;CI =&amp; get_instance();
      }
  
      private function connect() {
          $this-&gt;CI-&gt;load-&gt;database();
      }
  
      private function disconnect() {
          $this-&gt;CI-&gt;db-&gt;close();
      }
  
      public function getRecCenterInfo() {
          $this-&gt;connect();
  
          var_dump("Made it here");
          $result = $CI-&gt;db-&gt;query("SELECT * FROM ucfitness");
          var_dump($result-&gt;result());
  
          $this-&gt;disconnect();
          return $result-&gt;num_rows();
      }
  
  
  }
  </code></pre>
  
  <p>Here are a couple of additional configuration items, so you know what all I've done to customize it a bit.</p>
  
  <p>application/config/autoload.php</p>
  
  <pre><code>$autoload['helper'] = array('form', 'url');
  </code></pre>
  
  <p>webroot/index.php (For environment definitions)</p>
  
  <pre><code>if(isset($_SERVER['HTTP_HOST']) &amp;&amp; $_SERVER['HTTP_HOST'] == "my prod server") {
      define('ENVIRONMENT', 'prod');  
  } else if(isset($_SERVER['HTTP_HOST']) &amp;&amp; $_SERVER['HTTP_HOST'] == "my stage server") {
      define('ENVIRONMENT', 'stage'); 
  } else {
      define('ENVIRONMENT', 'test');  
  }
  
  if (defined('ENVIRONMENT'))
  {
      switch (ENVIRONMENT)
      {
          case 'test':
              error_reporting(E_ALL);
          break;
  
          case 'stage':
          case 'prod':
              error_reporting(0);
          break;
  
          default:
              exit('The application environment is not set correctly.');
      }
  }
  </code></pre>
  
  <p>I've also copied <code>application/config/database.php</code> into three folders, <code>application/config/test/database.php</code>, <code>application/config/stage/database.php</code>, and <code>application/config/prod/database.php</code>, to configure their individual connection parameters. Each environment has a different database server and credentials.</p>
  
  <p>The problem is that when I submit the form and it makes it in to that else statement after the form validation <code>$this-&gt;form_validation-&gt;run()</code> I'm getting only a blank screen. None of my desperate <code>var_dump</code>s, nothing. So, after all of my attempts and different methods of getting this to work, a few questions have come up.</p>
  
  <ol>
  <li>What isn't working in the library? After going through all the tutorials/questions that I can find, it looks like I'm doing it right.</li>
  <li>How do I make it so that I can actually debug the code? I get no errors in the browser and no errors on the Apache error log. What else can I do?</li>
  <li>What would the best practice be for separating the DAO from the Controller? From what I could tell, making this a library like I'm trying would be the best idea. It is probably only going to be used by this one controller, which will handle both registration and modification of the registration. I will be writing a couple of other applications that will all sit within this CI instance, but they're going to be fairly separate and will not need to use the same DAO.</li>
  <li>Can I use CamelCase for the library file name as long as it starts with a capital letter? <code>Reccenterdao.php</code> is a lot less friendly than <code>RecCenterDAO.php</code>. </li>
  </ol>
  
  <p>============================================================</p>
  
  <p>EDIT: I changed the whole thing to a model, but I'm getting the same functionality - blank screen with no errors. It seems to load the model, because it dies when I try to actually use it with the line <code>$numRows = $this-&gt;dao-&gt;getRecCenterInfo();</code></p>
  
  <p>I know the whole thing is pointless right now because I haven't put functionality to use the database or parse the user input. That's the whole point. I was trying to get it to work before I went through the effort of putting in all my business logic.</p>
  
  <p>application/models/rec_center_dao.php</p>
  
  <pre><code>class Rec_center_dao extends CI_Model {
  
      public function __construct() { 
          parent::__construct();
      }
  
      private function connect() {
          $this-&gt;load-&gt;database();
      }
  
      private function disconnect() {
          $this-&gt;db-&gt;close();
      }
  
      public function getRecCenterInfo() {
          $this-&gt;connect();
  
          var_dump("Made it here");
          $result = $this-&gt;db-&gt;query("SELECT * FROM ucfitness");
          var_dump($result-&gt;result());
  
          $this-&gt;disconnect();
          return $result-&gt;num_rows();
      }
  }
  </code></pre>
  
  <p>Relevant section of application/controllers/reccenter.php</p>
  
  <pre><code>    if ($this-&gt;form_validation-&gt;run() == FALSE) {
          $this-&gt;load-&gt;view('templates/header', $data);
          $this-&gt;load-&gt;view('pages/reccenter/register', $data);
          $this-&gt;load-&gt;view('templates/footer', $data);
      } else {
          $this-&gt;load-&gt;model('Rec_center_dao', 'dao');
          $numRows = $this-&gt;dao-&gt;getRecCenterInfo(); // This is where it dies
          var_dump($numRows);
  
          // Check if already registered 
              // Redirect to different view to change their registration
  
          // Do the registration
              //redirect('reccenter/confirm');
      }
  </code></pre>
  
  <p>============================================================</p>
  
  <p>EDIT2: Thanks to the comments, I've figured out that it's a problem connecting to the database. It errors out when I call <code>$this-&gt;load-&gt;database();</code>. I've confirmed that with the credentials I have I can manage the database with phpMyAdmin (I don't have shell access to test there). </p>
  
  <p>application/config/test/database.php</p>
  
  <pre><code>$active_group = 'default';
  $active_record = TRUE;
  
  $db['default']['hostname'] = 'my.hostname.com';
  $db['default']['username'] = 'db_username';
  $db['default']['password'] = 'db_password';
  $db['default']['database'] = 'db'
  $db['default']['dbdriver'] = 'mysql';
  $db['default']['dbprefix'] = '';
  $db['default']['pconnect'] = TRUE;
  $db['default']['db_debug'] = TRUE;
  $db['default']['cache_on'] = FALSE;
  $db['default']['cachedir'] = '';
  $db['default']['char_set'] = 'utf8';
  $db['default']['dbcollat'] = 'utf8_general_ci';
  $db['default']['swap_pre'] = '';
  $db['default']['autoinit'] = TRUE;
  $db['default']['stricton'] = TRUE;
  </code></pre>
  
  <p>With the above configurations in <code>webroot/index.php</code> and <code>application/config/test/database.php</code> it should pick up the settings for the different environments and take care of it accordingly, correct? But if I put a <code>var_dump</code> in either <code>application/config/database.php</code> or <code>application/config/test/database.php</code> it doesn't show up at all. I confirmed that the environment is being set correctly (at least while I'm working on test).</p>