Codeigniter, blank page, no errors [closed]

2019-02-19 11:07发布

问题:

public function newreg()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $this->load->model('register_model');

        $data['list']=$this->register_model->add($username, $password);

        $this->load->view('register_display', $data);
    }

This is part of a controller named register.php once this function gets called, all I see on the screen is white space.

This function is an exact copy of a working one, from a working controller. Only the file names are changed (model, view)

I can't figure out where the problem is.

回答1:

You can easly check what's happening in the enteire envoirment by enalbing CI logs,

go to config/config.php and edit this:

/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
|   0 = Disables logging, Error logging TURNED OFF
|   1 = Error Messages (including PHP errors)
|   2 = Debug Messages
|   3 = Informational Messages
|   4 = All Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/


  $config['log_threshold'] = 0; //put this to 4

then if you have not yet a /logs folder inside your /application folder, create that and add 775 chmod to that (logs folder only).

UPDATE: You must also chown apache:apache logs in order for apache to be able to write within that folder.

run your application by the browser and check inside your /logs folder the log.php file, it will contain all the application errors.



回答2:

To see the errors instead of a white page, you need to change two options in the php.ini file:

  • error_reporting to E_ALL
  • display_error to On

See this answer for more information.



回答3:

if you changed the file names, you also need to change the class names:

A file named my_class.php needs to have: class My_class extends CI_Controller {

so, if you took a working controller, copied it, and renamed the file. Then you also need to rename the class.