9

Hey, not sure why CodeIgniter is giving me a blank page when I load a simple model. I'm breaking the code down, backwards, and I can't figure out what's breaking. Here's the controller:

class Leads extends Controller {

function Leads() {
    parent::Controller();
    $this->load->scaffolding('leads');
  }

function index() {
    $data = array( 'title' => 'Lead Management' );

    $this->load->view('html_head', $data);
    $this->load->view('leads/home');
    $this->load->view('html_foot');

  }

function view() {
    $this->load->model('Leads');
    $this->load->view('html_head');
    $this->load->view('leads/view');
    $this->load->view('html_foot');
  }

}

Here's the model:

class Leads extends Model {

function Leads()    {
    parent::Model();
}

}

The only way I don't get a white page on /view is if I comment out the loading of the model. I have absolutely no idea what I'm doing wrong, I'm copying the examples and structure literally right off the CI site.

tereško
  • 58,060
  • 25
  • 98
  • 150
dmanexe
  • 1,034
  • 4
  • 16
  • 40

7 Answers7

16

Ah, the classic Codeigniter white screen of death. I ran into this the first time I used CI. Unbelievably frustrating that such a popular framework could cause something like this with no error output.

In my particular case, it was because I attempted to use the Database class with MySQLi, but my target environment didn't have the MySQLi module installed. For some reason, CI suppressed all the usual error output, so it turned a 2-minute investigation into a 2-hour investigation.

So that being said, I'd check the following things:

  • error_reporting set to E_ALL in your php.ini, and display_errors is on.
  • Turn on log_errors as well.
  • Check that the classes you're using don't rely on a special PHP module that you might not have

If you can't find anything with error output, you're going to have to dig deeper. If you have xdebug installed, I'd highly suggest using that... surround your code in a trace and see where it's choking.

I ended up having to find the cause of my WSOD by drilling down through the framework classes itself and dumping output (no xdebug was available). It's not fun, but it eventually worked.

zombat
  • 92,731
  • 24
  • 156
  • 164
  • True! :) Following your advice I went to `C:\Apache2.2\htdocs\Cofix3D\application\config\database.php`and removed the db settings and finally got an error message when trying to load the page again: `No database connection settings were found in the database config file.` Now let me install MySQL and configure it appropriately. :D – Leniel Maccaferri Aug 20 '12 at 20:41
12

Both your classes are named "Leads". When CI includes these, they are loaded into the same namespace. You probably have a "Cannot redeclare class 'Leads'" error. Try renaming the model and you should be fine.

Edit: guess confirmed

Dan Soap
  • 10,114
  • 1
  • 40
  • 49
  • YES!!!! Thank you so much! This was exactly the problem. This should be noted in the documentation and user guide, it was no where to be found. – dmanexe Jan 27 '10 at 19:15
  • **Chuckles** If I hadn't already given you +1 you'd have earned it for the _guess confirmed_ – Sean Vieira Jan 27 '10 at 19:20
  • Nice, +1 from me too. I didn't even see that. I find CI's error handling sub-par. Why can't it give you error output in situations like this? – zombat Jan 27 '10 at 20:30
  • 2
    I think mainly because it is a fatal error. CI tries to output every error using it's "beautiful" template, but by definition it cannot handle Fatal Errors. – Dan Soap Jan 31 '10 at 21:59
  • Would this not show up in the server's error logs? That's usually the first place I check when I get a WSOD – stef Dec 07 '10 at 21:47
2

I differentiate my controllers and models by adding the names _controller or _model to the classes. This eliminates confusion of classes. Try renaming them like
Leads_Controler and Leads_Model.

Mathayo
  • 39
  • 1
  • 3
2

As Cassy guessed, it is a problem with your naming -- CI cannot deal with models and controllers having the same name. Rename you Leads model to something else and try reloading the page. That should fix the problem.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
1

Another reason for White screen of death is enabling query caching or log lutputtibg with the respective folder not being writeable. That's got me a few times!

Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
1

Just solved the same issue after a very unpleasant night spent stumblin' around into CI libraries.

As Zombat pointed out, my problem was I forgot to install the php5-mysql module in my linux box.

Once apt-get installed the mysql module everything started playing as expected.

Noob, I know. But i would expect a better behaviour by CI in handling such kind of exceptions. A single line of log would have saved a bunch of hours and curses.

MariusPontmercy
  • 398
  • 1
  • 5
  • 20
0

I had a white blank page after using my first model. The solution is if you use Codeigniter 2+ you need to extend from CI_Model instead of Model. so the Class of a model should say class myModel extends CI_Model. That helped for me after 4 hours of search.

Firo
  • 30,626
  • 4
  • 55
  • 94